mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Refs #24686 -- Made AlterField operation a noop when renaming related model with db_table.
This commit is contained in:
parent
07b7a3ab75
commit
f05cc5e3d2
@ -1601,10 +1601,20 @@ class BaseDatabaseSchemaEditor:
|
||||
# - changing an attribute that doesn't affect the schema
|
||||
# - changing an attribute in the provided set of ignored attributes
|
||||
# - adding only a db_column and the column name is not changed
|
||||
# - db_table does not change for model referenced by foreign keys
|
||||
for attr in ignore.union(old_field.non_db_attrs):
|
||||
old_kwargs.pop(attr, None)
|
||||
for attr in ignore.union(new_field.non_db_attrs):
|
||||
new_kwargs.pop(attr, None)
|
||||
if (
|
||||
not new_field.many_to_many
|
||||
and old_field.remote_field
|
||||
and new_field.remote_field
|
||||
and old_field.remote_field.model._meta.db_table
|
||||
== new_field.remote_field.model._meta.db_table
|
||||
):
|
||||
old_kwargs.pop("to", None)
|
||||
new_kwargs.pop("to", None)
|
||||
return self.quote_name(old_field.column) != self.quote_name(
|
||||
new_field.column
|
||||
) or (old_path, old_args, old_kwargs) != (new_path, new_args, new_kwargs)
|
||||
|
@ -997,6 +997,18 @@ class OperationTests(OperationTestBase):
|
||||
with connection.schema_editor() as editor, self.assertNumQueries(0):
|
||||
operation.database_forwards(app_label, editor, project_state, new_state)
|
||||
|
||||
@skipUnlessDBFeature("supports_foreign_keys")
|
||||
def test_rename_model_with_db_table_and_fk_noop(self):
|
||||
app_label = "test_rmwdbtfk"
|
||||
project_state = self.set_up_test_model(
|
||||
app_label, db_table="my_pony", related_model=True
|
||||
)
|
||||
new_state = project_state.clone()
|
||||
operation = migrations.RenameModel("Pony", "LittleHorse")
|
||||
operation.state_forwards(app_label, new_state)
|
||||
with connection.schema_editor() as editor, self.assertNumQueries(0):
|
||||
operation.database_forwards(app_label, editor, project_state, new_state)
|
||||
|
||||
def test_rename_model_with_self_referential_m2m(self):
|
||||
app_label = "test_rename_model_with_self_referential_m2m"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user