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

Fixed #31826 -- Made AlterField operation a noop when adding db_column.

AlterField operation with adding a db_column is a noop if the column
name is not changed.
This commit is contained in:
Iuri de Silvio
2020-07-25 10:42:43 -03:00
committed by Mariusz Felisiak
parent 3a6fa1d962
commit 632ccffc49
2 changed files with 61 additions and 2 deletions

View File

@@ -1037,10 +1037,16 @@ class BaseDatabaseSchemaEditor:
return output
def _field_should_be_altered(self, old_field, new_field):
# Don't alter when changing only a field name.
_, old_path, old_args, old_kwargs = old_field.deconstruct()
_, new_path, new_args, new_kwargs = new_field.deconstruct()
# Don't alter when:
# - changing only a field name
# - adding only a db_column and the column name is not changed
old_kwargs.pop('db_column', None)
new_kwargs.pop('db_column', None)
return (
old_field.column != new_field.column or
old_field.deconstruct()[1:] != new_field.deconstruct()[1:]
(old_path, old_args, old_kwargs) != (new_path, new_args, new_kwargs)
)
def _field_should_be_indexed(self, model, field):