From 55fa4c2d3423b051fce5663b3efc13e458fbb777 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 8 Jun 2014 17:12:27 -0700 Subject: [1.7.x] Fixed #22777: Add dependency on through for autodetected M2M adds --- tests/migrations/test_autodetector.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index 6d163873ad..f969ae50ac 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -77,7 +77,7 @@ class AutodetectorTests(TestCase): def assertNumberMigrations(self, changes, app_label, number): if len(changes.get(app_label, [])) != number: self.fail("Incorrect number of migrations (%s) for %s (expected %s)\n%s" % ( - len(changes[app_label]), + len(changes.get(app_label, [])), app_label, number, self.repr_changes(changes), @@ -694,6 +694,20 @@ class AutodetectorTests(TestCase): self.assertEqual(action.__class__.__name__, "AddField") self.assertEqual(action.name, "publishers") + def test_create_with_through_model(self): + """ + Adding a m2m with a through model and the models that use it should + be ordered correctly. + """ + before = self.make_project_state([]) + after = self.make_project_state([self.author_with_m2m_through, self.publisher, self.contract]) + autodetector = MigrationAutodetector(before, after) + changes = autodetector._detect_changes() + # Right number of migrations? + self.assertNumberMigrations(changes, "testapp", 1) + # Right actions in right order? + self.assertOperationTypes(changes, "testapp", 0, ["CreateModel", "CreateModel", "CreateModel", "AddField", "AddField"]) + def test_many_to_many_removed_before_through_model(self): """ Removing a ManyToManyField and the "through" model in the same change must remove -- cgit v1.3