diff options
author | DevilsAutumn <bhuvnesh875@gmail.com> | 2022-11-11 00:13:16 +0530 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-11-17 12:36:52 +0100 |
commit | 81b1c167bf919ddbd5aa0289f9f3761fc62addf3 (patch) | |
tree | f421c93358197259ce9ea21cc04f2a2db5e8611c /tests/migrations | |
parent | 2848e5d0ce5cf3c31fe87525536093b21d570f69 (diff) | |
download | django-81b1c167bf919ddbd5aa0289f9f3761fc62addf3.tar.gz |
Fixed #28987 -- Fixed altering ManyToManyField when changing to self-referential.
Diffstat (limited to 'tests/migrations')
-rw-r--r-- | tests/migrations/test_operations.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index e02dc9ef3f..dc0d34eebd 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -1796,6 +1796,43 @@ class OperationTests(OperationTestBase): self.assertTableExists(original_m2m_table) self.assertTableNotExists(new_m2m_table) + def test_alter_model_table_m2m_field(self): + app_label = "test_talm2mfl" + project_state = self.set_up_test_model(app_label, second_model=True) + # Add the M2M field. + project_state = self.apply_operations( + app_label, + project_state, + operations=[ + migrations.AddField( + "Pony", + "stables", + models.ManyToManyField("Stable"), + ) + ], + ) + m2m_table = f"{app_label}_pony_stables" + self.assertColumnExists(m2m_table, "pony_id") + self.assertColumnExists(m2m_table, "stable_id") + # Point the M2M field to self. + with_field_state = project_state.clone() + operations = [ + migrations.AlterField( + model_name="Pony", + name="stables", + field=models.ManyToManyField("self"), + ) + ] + project_state = self.apply_operations( + app_label, project_state, operations=operations + ) + self.assertColumnExists(m2m_table, "from_pony_id") + self.assertColumnExists(m2m_table, "to_pony_id") + # Reversal. + self.unapply_operations(app_label, with_field_state, operations=operations) + self.assertColumnExists(m2m_table, "pony_id") + self.assertColumnExists(m2m_table, "stable_id") + def test_alter_field(self): """ Tests the AlterField operation. |