summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorDevilsAutumn <bhuvnesh875@gmail.com>2023-02-10 16:32:31 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-02-14 14:33:45 +0100
commit5cde08f702c1db7646c0c1c8f9d72d01067310df (patch)
tree2a4617e29517224159faa1daa12110cb6a27ad41 /django
parentb7aab1fb3a41b13ab5d7e19ae9891ed02b9390ce (diff)
[4.2.x] Fixed #34250 -- Fixed renaming model with m2m relation to a model with the same name.
Backport of ff3a2834224f527ca574b5cd0d578c8c26d51a6c from main
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/operations/models.py20
1 files changed, 6 insertions, 14 deletions
diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py
index 8847441a03..967a91fdc8 100644
--- a/django/db/migrations/operations/models.py
+++ b/django/db/migrations/operations/models.py
@@ -407,20 +407,12 @@ class RenameModel(ModelOperation):
or not new_field.remote_field.through._meta.auto_created
):
continue
- # Rename the M2M table that's based on this model's name.
- old_m2m_model = old_field.remote_field.through
- new_m2m_model = new_field.remote_field.through
- schema_editor.alter_db_table(
- new_m2m_model,
- old_m2m_model._meta.db_table,
- new_m2m_model._meta.db_table,
- )
- # Rename the column in the M2M table that's based on this
- # model's name.
- schema_editor.alter_field(
- new_m2m_model,
- old_m2m_model._meta.get_field(old_model._meta.model_name),
- new_m2m_model._meta.get_field(new_model._meta.model_name),
+ # Rename columns and the M2M table.
+ schema_editor._alter_many_to_many(
+ new_model,
+ old_field,
+ new_field,
+ strict=False,
)
def database_backwards(self, app_label, schema_editor, from_state, to_state):