diff options
| author | Johanan Oppong Amoateng <johananoppongamoateng2001@gmail.com> | 2025-12-12 23:17:38 +0000 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-12-19 14:01:37 -0500 |
| commit | 33a0a6f033b9243e0cc98e76bd494de73cf144eb (patch) | |
| tree | 3883721f41d95d2e332a6988a99d494f55ba1f62 /tests/migrations | |
| parent | 948f1bf5a1c1c93ee9c6f4baa2fd990e31361f81 (diff) | |
Fixed #36791 -- Made MigrationAutodetector recreate through table when m2m target model changes.
Co-Authored-By: Jacob Walls <38668450+jacobtylerwalls@users.noreply.github.com>
Co-Authored-By: Clifford Gama <cliffygamy@gmail.com>
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 |
