mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #24435 -- Prevented m2m field removal and addition in migrations when changing blank
Thanks Mark Tranchant for the report an Tim Graham for the test and review.
This commit is contained in:
@@ -127,6 +127,10 @@ class AutodetectorTests(TestCase):
|
||||
("id", models.AutoField(primary_key=True)),
|
||||
("publishers", models.ManyToManyField("testapp.Publisher")),
|
||||
])
|
||||
author_with_m2m_blank = ModelState("testapp", "Author", [
|
||||
("id", models.AutoField(primary_key=True)),
|
||||
("publishers", models.ManyToManyField("testapp.Publisher", blank=True)),
|
||||
])
|
||||
author_with_m2m_through = ModelState("testapp", "Author", [
|
||||
("id", models.AutoField(primary_key=True)),
|
||||
("publishers", models.ManyToManyField("testapp.Publisher", through="testapp.Contract")),
|
||||
@@ -1263,6 +1267,16 @@ class AutodetectorTests(TestCase):
|
||||
self.assertOperationTypes(changes, 'testapp', 0, ["AddField"])
|
||||
self.assertOperationAttributes(changes, 'testapp', 0, 0, name="publishers")
|
||||
|
||||
def test_alter_many_to_many(self):
|
||||
before = self.make_project_state([self.author_with_m2m, self.publisher])
|
||||
after = self.make_project_state([self.author_with_m2m_blank, self.publisher])
|
||||
autodetector = MigrationAutodetector(before, after)
|
||||
changes = autodetector._detect_changes()
|
||||
# Right number/type of migrations?
|
||||
self.assertNumberMigrations(changes, 'testapp', 1)
|
||||
self.assertOperationTypes(changes, 'testapp', 0, ["AlterField"])
|
||||
self.assertOperationAttributes(changes, 'testapp', 0, 0, name="publishers")
|
||||
|
||||
def test_create_with_through_model(self):
|
||||
"""
|
||||
Adding a m2m with a through model and the models that use it should be
|
||||
|
||||
Reference in New Issue
Block a user