From 41b337efa085b6b9cfdb2cf724d977005ff77e75 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 22 Oct 2014 09:59:00 -0400 Subject: Fixed #23630 -- Made AlterModelTable rename auto-created M2M tables. Thanks Naddiseo for the report, Andrew Godwin for guidance, and Shai Berger for review. --- django/db/migrations/operations/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'django') diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py index eade3ee878..0e4a1a50f5 100644 --- a/django/db/migrations/operations/models.py +++ b/django/db/migrations/operations/models.py @@ -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) -- cgit v1.3