1
0
mirror of https://github.com/django/django.git synced 2025-10-27 15:46:10 +00:00

[1.7.x] Fixed #22777: Add dependency on through for autodetected M2M adds

This commit is contained in:
Andrew Godwin
2014-06-08 17:12:27 -07:00
parent 25f4e71ed3
commit 55fa4c2d34
3 changed files with 36 additions and 9 deletions

View File

@@ -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