summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_operations.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 33b76984d4..64e29194ca 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -1308,6 +1308,51 @@ class OperationTests(OperationTestBase):
operation.database_backwards("test_alflpkfk", editor, new_state, project_state)
assertIdTypeEqualsFkType()
+ @skipUnlessDBFeature('supports_foreign_keys')
+ def test_alter_field_reloads_state_on_fk_with_to_field_target_type_change(self):
+ app_label = 'alter_field_reloads_state_on_fk_with_to_field_target_type_change'
+ project_state = self.apply_operations(app_label, ProjectState(), operations=[
+ migrations.CreateModel('Rider', fields=[
+ ('id', models.AutoField(primary_key=True)),
+ ('code', models.PositiveIntegerField(unique=True)),
+ ]),
+ migrations.CreateModel('Pony', fields=[
+ ('id', models.AutoField(primary_key=True)),
+ ('rider', models.ForeignKey('%s.Rider' % app_label, models.CASCADE, to_field='code')),
+ ]),
+ ])
+ operation = migrations.AlterField(
+ 'Rider',
+ 'code',
+ models.CharField(max_length=100, unique=True),
+ )
+ self.apply_operations(app_label, project_state, operations=[operation])
+
+ @skipUnlessDBFeature('supports_foreign_keys')
+ def test_alter_field_reloads_state_on_fk_with_to_field_related_name_target_type_change(self):
+ app_label = 'alter_field_reloads_state_on_fk_with_to_field_rn_target_type_change'
+ project_state = self.apply_operations(app_label, ProjectState(), operations=[
+ migrations.CreateModel('Rider', fields=[
+ ('id', models.AutoField(primary_key=True)),
+ ('code', models.PositiveIntegerField(unique=True)),
+ ]),
+ migrations.CreateModel('Pony', fields=[
+ ('id', models.AutoField(primary_key=True)),
+ ('rider', models.ForeignKey(
+ '%s.Rider' % app_label,
+ models.CASCADE,
+ to_field='code',
+ related_name='+',
+ )),
+ ]),
+ ])
+ operation = migrations.AlterField(
+ 'Rider',
+ 'code',
+ models.CharField(max_length=100, unique=True),
+ )
+ self.apply_operations(app_label, project_state, operations=[operation])
+
def test_alter_field_reloads_state_on_fk_target_changes(self):
"""
If AlterField doesn't reload state appropriately, the second AlterField