summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3/schema.py
diff options
context:
space:
mode:
authorHampus Dunström <hampus@dunstrom.com>2018-10-25 13:22:40 +0200
committerTim Graham <timograham@gmail.com>2018-10-27 20:26:39 -0400
commit5e8a07d69dee354d9e6dbda874f9454f4bc3491e (patch)
tree1828f6c66429ad7fb8e703822ce43c0cda5d02ec /django/db/backends/sqlite3/schema.py
parent4c13b907023692f75f37ba980cf2215e413aa1d8 (diff)
Fixed #29763 -- Added support for column renaming on SQLite.
Diffstat (limited to 'django/db/backends/sqlite3/schema.py')
-rw-r--r--django/db/backends/sqlite3/schema.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py
index 8710e9d0e2..99382d35ce 100644
--- a/django/db/backends/sqlite3/schema.py
+++ b/django/db/backends/sqlite3/schema.py
@@ -331,6 +331,14 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
def _alter_field(self, model, old_field, new_field, old_type, new_type,
old_db_params, new_db_params, strict=False):
"""Perform a "physical" (non-ManyToMany) field update."""
+ # Use "ALTER TABLE ... RENAME COLUMN" if only the column name
+ # changed and there aren't any constraints.
+ if (self.connection.features.can_alter_table_rename_column and
+ old_field.column != new_field.column and
+ self.column_sql(model, old_field) == self.column_sql(model, new_field) and
+ not (old_field.remote_field and old_field.db_constraint or
+ new_field.remote_field and new_field.db_constraint)):
+ return self.execute(self._rename_field_sql(model._meta.db_table, old_field, new_field, new_type))
# Alter by remaking table
self._remake_table(model, alter_field=(old_field, new_field))
# Rebuild tables with FKs pointing to this field if the PK type changed.