diff options
Diffstat (limited to 'tests/migrations')
| -rw-r--r-- | tests/migrations/test_autodetector.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index c044cc9a99..e333621855 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -741,6 +741,13 @@ class AutodetectorTests(BaseAutodetectorTests): ("publishers", models.ManyToManyField("testapp.Publisher", blank=True)), ], ) + other_publisher = ModelState( + "testapp", + "OtherPublisher", + [ + ("id", models.AutoField(primary_key=True)), + ], + ) author_with_m2m_through = ModelState( "testapp", "Author", @@ -4557,6 +4564,46 @@ class AutodetectorTests(BaseAutodetectorTests): ) self.assertOperationFieldAttributes(changes, "testapp", 0, 2, max_length=100) + def test_m2m_target_change_generates_remove_and_add(self): + before = [ + self.publisher, + self.other_publisher, + self.author_with_m2m, # m2m to self.publisher. + ] + + after = [ + self.publisher, + self.other_publisher, + ModelState( + "testapp", + "Author", + [ + ("id", models.AutoField(primary_key=True)), + # Repoint m2m to self.other_publisher. + ("publishers", models.ManyToManyField("testapp.OtherPublisher")), + ], + ), + ] + changes = self.get_changes(before, after) + self.assertNumberMigrations(changes, "testapp", 1) + self.assertOperationTypes(changes, "testapp", 0, ["RemoveField", "AddField"]) + self.assertOperationAttributes( + changes, + "testapp", + 0, + 0, + name="publishers", + model_name="author", + ) + self.assertOperationAttributes( + changes, + "testapp", + 0, + 1, + name="publishers", + model_name="author", + ) + def test_non_circular_foreignkey_dependency_removal(self): """ If two models with a ForeignKey from one to the other are removed at |
