summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAna Vojnovic <ana.vojnovic@dobarkod.hr>2015-11-07 15:26:25 +0100
committerTim Graham <timograham@gmail.com>2015-11-20 12:20:41 -0500
commit73a6ab6382809d5452907dcff5767403d8d66985 (patch)
tree2d8acfb091009e9be4effce3b412ef49bd85f8a2 /tests
parent8092745593e2aa7b54c6de44d12a893772ace3e9 (diff)
Fixed #25551 -- Fixed migration operations ordering when adding fields and a unique_together constraint.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 40ad1d450c..1ed74226f8 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -1174,6 +1174,34 @@ class AutodetectorTests(TestCase):
self.assertOperationAttributes(changes, "otherapp", 0, 1, name="book", unique_together={("title", "newfield")})
self.assertOperationAttributes(changes, "otherapp", 0, 2, name="book", index_together={("title", "newfield")})
+ def test_create_model_and_unique_together(self):
+ author = ModelState("otherapp", "Author", [
+ ("id", models.AutoField(primary_key=True)),
+ ("name", models.CharField(max_length=200)),
+ ])
+ book_with_author = ModelState("otherapp", "Book", [
+ ("id", models.AutoField(primary_key=True)),
+ ("author", models.ForeignKey("otherapp.Author", models.CASCADE)),
+ ("title", models.CharField(max_length=200)),
+ ], {
+ "index_together": {("title", "author")},
+ "unique_together": {("title", "author")},
+ })
+ before = self.make_project_state([self.book_with_no_author])
+ after = self.make_project_state([author, book_with_author])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+ # Right number of migrations?
+ self.assertEqual(len(changes['otherapp']), 1)
+ # Right number of actions?
+ migration = changes['otherapp'][0]
+ self.assertEqual(len(migration.operations), 4)
+ # Right actions order?
+ self.assertOperationTypes(
+ changes, 'otherapp', 0,
+ ['CreateModel', 'AddField', 'AlterUniqueTogether', 'AlterIndexTogether']
+ )
+
def test_remove_field_and_foo_together(self):
"""
Tests that removed fields will be removed after updating