1
0
mirror of https://github.com/django/django.git synced 2025-10-27 15:46:10 +00:00

Fixed #23630 -- Made AlterModelTable rename auto-created M2M tables.

Thanks Naddiseo for the report, Andrew Godwin for guidance,
and Shai Berger for review.
This commit is contained in:
Tim Graham
2014-10-22 09:59:00 -04:00
parent 22c85bf1a8
commit 41b337efa0
3 changed files with 46 additions and 2 deletions

View File

@@ -212,6 +212,14 @@ class AlterModelTable(Operation):
old_model._meta.db_table,
new_model._meta.db_table,
)
# Rename M2M fields whose name is based on this model's db_table
for (old_field, new_field) in zip(old_model._meta.local_many_to_many, new_model._meta.local_many_to_many):
if new_field.rel.through._meta.auto_created:
schema_editor.alter_db_table(
new_field.rel.through,
old_field.rel.through._meta.db_table,
new_field.rel.through._meta.db_table,
)
def database_backwards(self, app_label, schema_editor, from_state, to_state):
return self.database_forwards(app_label, schema_editor, from_state, to_state)