diff options
| author | Iuri de Silvio <iurisilvio@gmail.com> | 2020-07-24 18:08:40 -0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-08-13 13:14:58 +0200 |
| commit | 7f4c9222dfe2f28ff8a7ffc56c28ccbadf19cf6f (patch) | |
| tree | 878f533d578acfe752047fc7da1c9a0265a6f727 /django | |
| parent | 20799cc0a6d98816b9ef0577e24691bd26b80d7d (diff) | |
Fixed #31825 -- Made RenameField operation a noop for fields with db_column.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/base/schema.py | 9 | ||||
| -rw-r--r-- | django/db/backends/sqlite3/schema.py | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/django/db/backends/base/schema.py b/django/db/backends/base/schema.py index c8dc8e3a70..d988fca903 100644 --- a/django/db/backends/base/schema.py +++ b/django/db/backends/base/schema.py @@ -538,6 +538,8 @@ class BaseDatabaseSchemaEditor: If `strict` is True, raise errors if the old column does not match `old_field` precisely. """ + if not self._field_should_be_altered(old_field, new_field): + return # Ensure this field is even column-based old_db_params = old_field.db_parameters(connection=self.connection) old_type = old_db_params['type'] @@ -1034,6 +1036,13 @@ class BaseDatabaseSchemaEditor: output.append(self._create_index_sql(model, [field])) return output + def _field_should_be_altered(self, old_field, new_field): + # Don't alter when changing only a field name. + return ( + old_field.column != new_field.column or + old_field.deconstruct()[1:] != new_field.deconstruct()[1:] + ) + def _field_should_be_indexed(self, model, field): return field.db_index and not field.unique diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py index aca5d61b39..146ad18f84 100644 --- a/django/db/backends/sqlite3/schema.py +++ b/django/db/backends/sqlite3/schema.py @@ -99,6 +99,8 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): super().alter_db_table(model, old_db_table, new_db_table) def alter_field(self, model, old_field, new_field, strict=False): + if not self._field_should_be_altered(old_field, new_field): + return old_field_name = old_field.name table_name = model._meta.db_table _, old_column_name = old_field.get_attname_column() |
