1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[4.1.x] Fixed #33953 -- Reverted "Fixed #33201 -- Made RenameModel operation a noop for models with db_table."

Regression in afeafd6036.
This reverts afeafd6036.

Thanks Timothy Thomas for the report.

Backport of 166a3b3263 from main
This commit is contained in:
Iuri de Silvio
2022-08-24 10:10:56 -03:00
committed by Mariusz Felisiak
parent c9ebd5b7aa
commit 7d5ccbbe1a
3 changed files with 20 additions and 22 deletions

View File

@@ -371,13 +371,12 @@ class RenameModel(ModelOperation):
new_model = to_state.apps.get_model(app_label, self.new_name)
if self.allow_migrate_model(schema_editor.connection.alias, new_model):
old_model = from_state.apps.get_model(app_label, self.old_name)
old_db_table = old_model._meta.db_table
new_db_table = new_model._meta.db_table
# Don't alter when a table name is not changed.
if old_db_table == new_db_table:
return
# Move the main table
schema_editor.alter_db_table(new_model, old_db_table, new_db_table)
schema_editor.alter_db_table(
new_model,
old_model._meta.db_table,
new_model._meta.db_table,
)
# Alter the fields pointing to us
for related_object in old_model._meta.related_objects:
if related_object.related_model == old_model: