From 13aa079941dcfd953ba03a83f55c8a14399d15c2 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 15 Jun 2014 12:06:48 -0700 Subject: [1.7.x] Fixed #22833: Autodetector not doing through mapping correctly --- tests/migrations/test_autodetector.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index f969ae50ac..48c76d1bca 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -738,6 +738,21 @@ class AutodetectorTests(TestCase): self.assertEqual(action.__class__.__name__, "DeleteModel") self.assertEqual(action.name, "Attribution") + def test_many_to_many_removed_before_through_model_2(self): + """ + Removing a model that contains a ManyToManyField and the + "through" model in the same change must remove + the field before the model to maintain consistency. + """ + before = self.make_project_state([self.book_with_multiple_authors_through_attribution, self.author_name, self.attribution]) + after = self.make_project_state([self.author_name]) # removes both the through model and ManyToMany + autodetector = MigrationAutodetector(before, after) + changes = autodetector._detect_changes() + # Right number of migrations? + self.assertNumberMigrations(changes, 'otherapp', 1) + # Right number of actions? + self.assertOperationTypes(changes, 'otherapp', 0, ["RemoveField", "RemoveField", "RemoveField", "DeleteModel", "DeleteModel"]) + def test_m2m_w_through_multistep_remove(self): """ A model with a m2m field that specifies a "through" model cannot be removed in the same -- cgit v1.3