Ticket #31492: test.py

File test.py, 1.2 KB (added by felixxm, 5 months ago)
Line 
1@skipUnlessDBFeature('supports_foreign_keys')
2def test_alter_field_reloads_state_on_fk_with_to_field_target_type_change(self):
3    app_label = 'test_alflrsfkwtflttc'
4    project_state = self.apply_operations(app_label, ProjectState(), operations=[
5        migrations.CreateModel('Rider', fields=[
6            ('id', models.AutoField(primary_key=True)),
7            ('code', models.PositiveIntegerField(unique=True)),
8        ]),
9        migrations.CreateModel('Pony', fields=[
10            ('id', models.AutoField(primary_key=True)),
11            ('rider', models.ForeignKey('%s.Rider' % app_label, models.CASCADE, to_field='code')),
12        ]),
13    ])
14    operation = migrations.AlterField(
15        'Rider',
16        'code',
17        models.CharField(max_length=100, unique=True),
18    )
19    self.apply_operations(app_label, project_state, operations=[operation])
20    id_type, id_null = [
21        (c.type_code, c.null_ok)
22        for c in self.get_table_description('test_alflrsfkwtflttc_rider')
23        if c.name == 'code'
24    ][0]
25    fk_type, fk_null = [
26        (c.type_code, c.null_ok)
27        for c in self.get_table_description('test_alflrsfkwtflttc_pony')
28        if c.name == 'rider_id'
29    ][0]
30    self.assertEqual(id_type, fk_type)
31    self.assertEqual(id_null, fk_null)
Back to Top