summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2015-03-28 18:57:51 +0100
committerMarkus Holtermann <info@markusholtermann.eu>2015-03-28 20:45:15 +0100
commitc7ec3c07e78e288a48e87b979dbd12e1fa44fe66 (patch)
tree7f149cd0c4bcbd0e5ed37ce891f0c495e5bb72f9 /tests
parentba1665ed75264e57b7bc6cd7606e072ad3050a3b (diff)
downloaddjango-c7ec3c07e78e288a48e87b979dbd12e1fa44fe66.tar.gz
Fixed #24537 -- Ignored field order in RenameModel detection
Thanks to David Sanders for the report and test and Simon Charette for the review.
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 59654f9539..269d41fd2c 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -657,6 +657,37 @@ class AutodetectorTests(TestCase):
self.assertOperationTypes(changes, 'otherapp', 0, ["RenameField"])
self.assertOperationAttributes(changes, 'otherapp', 0, 0, old_name="author", new_name="writer")
+ def test_rename_model_with_fks_in_different_position(self):
+ """
+ #24537 - Tests that the order of fields in a model does not influence
+ the RenameModel detection.
+ """
+ before = self.make_project_state([
+ ModelState("testapp", "EntityA", [
+ ("id", models.AutoField(primary_key=True)),
+ ]),
+ ModelState("testapp", "EntityB", [
+ ("id", models.AutoField(primary_key=True)),
+ ("some_label", models.CharField(max_length=255)),
+ ("entity_a", models.ForeignKey("testapp.EntityA")),
+ ]),
+ ])
+ after = self.make_project_state([
+ ModelState("testapp", "EntityA", [
+ ("id", models.AutoField(primary_key=True)),
+ ]),
+ ModelState("testapp", "RenamedEntityB", [
+ ("id", models.AutoField(primary_key=True)),
+ ("entity_a", models.ForeignKey("testapp.EntityA")),
+ ("some_label", models.CharField(max_length=255)),
+ ]),
+ ])
+ autodetector = MigrationAutodetector(before, after, MigrationQuestioner({"ask_rename_model": True}))
+ changes = autodetector._detect_changes()
+ self.assertNumberMigrations(changes, "testapp", 1)
+ self.assertOperationTypes(changes, "testapp", 0, ["RenameModel"])
+ self.assertOperationAttributes(changes, "testapp", 0, 0, old_name="EntityB", new_name="RenamedEntityB")
+
def test_fk_dependency(self):
"""Tests that having a ForeignKey automatically adds a dependency."""
# Make state