summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeremy Satterfield <jsatt22@gmail.com>2017-08-17 16:41:04 -0500
committerTim Graham <timograham@gmail.com>2017-09-04 15:15:39 -0400
commit0891503fad458e7dfabc5adbf314f80e78e63f14 (patch)
tree9751f265caf5b4ec8315a38face009f005090818 /tests
parent3f2b1d926bb3a72b4c3d2cd958455ebb9b4ca458 (diff)
Fixed #28493 -- Made migrations autodetector find dependencies for model renaming.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 997c81f29e..74961048fb 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -901,6 +901,37 @@ class AutodetectorTests(TestCase):
self.assertOperationTypes(changes, "testapp", 0, ["RenameModel"])
self.assertOperationAttributes(changes, "testapp", 0, 0, old_name="EntityB", new_name="RenamedEntityB")
+ def test_rename_model_reverse_relation_dependencies(self):
+ """
+ The migration to rename a model pointed to by a foreign key in another
+ app must run after the other app's migration that adds the foreign key
+ with model's original name. Therefore, the renaming migration has a
+ dependency on that other migration.
+ """
+ before = [
+ ModelState('testapp', 'EntityA', [
+ ('id', models.AutoField(primary_key=True)),
+ ]),
+ ModelState('otherapp', 'EntityB', [
+ ('id', models.AutoField(primary_key=True)),
+ ('entity_a', models.ForeignKey('testapp.EntityA', models.CASCADE)),
+ ]),
+ ]
+ after = [
+ ModelState('testapp', 'RenamedEntityA', [
+ ('id', models.AutoField(primary_key=True)),
+ ]),
+ ModelState('otherapp', 'EntityB', [
+ ('id', models.AutoField(primary_key=True)),
+ ('entity_a', models.ForeignKey('testapp.RenamedEntityA', models.CASCADE)),
+ ]),
+ ]
+ changes = self.get_changes(before, after, MigrationQuestioner({'ask_rename_model': True}))
+ self.assertNumberMigrations(changes, 'testapp', 1)
+ self.assertMigrationDependencies(changes, 'testapp', 0, [('otherapp', '__first__')])
+ self.assertOperationTypes(changes, 'testapp', 0, ['RenameModel'])
+ self.assertOperationAttributes(changes, 'testapp', 0, 0, old_name='EntityA', new_name='RenamedEntityA')
+
def test_fk_dependency(self):
"""Having a ForeignKey automatically adds a dependency."""
# Note that testapp (author) has no dependencies,