diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-11 22:21:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-11 22:21:58 +0100 |
commit | 3702819227fd0cdd9b581cd99e11d1561d51cbeb (patch) | |
tree | dbb187f9d7c3c34ac647b4ddc614c8e67b813a89 /django/db/backends/sqlite3/schema.py | |
parent | d113b5a837f726d1c638d76c4e88445e6cd59fd5 (diff) | |
download | django-3702819227fd0cdd9b581cd99e11d1561d51cbeb.tar.gz |
Refs #32502 -- Avoided table rebuild when removing fields on SQLite 3.35.5+.
ALTER TABLE ... DROP COLUMN was introduced in SQLite 3.35+ however
a data corruption issue was fixed in SQLite 3.35.5.
Diffstat (limited to 'django/db/backends/sqlite3/schema.py')
-rw-r--r-- | django/db/backends/sqlite3/schema.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py index 18449026bd..b3a2f4282b 100644 --- a/django/db/backends/sqlite3/schema.py +++ b/django/db/backends/sqlite3/schema.py @@ -18,6 +18,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): "REFERENCES %(to_table)s (%(to_column)s) DEFERRABLE INITIALLY DEFERRED" ) sql_create_column_inline_fk = sql_create_inline_fk + sql_delete_column = "ALTER TABLE %(table)s DROP COLUMN %(column)s" sql_create_unique = "CREATE UNIQUE INDEX %(name)s ON %(table)s (%(columns)s)" sql_delete_unique = "DROP INDEX %(name)s" @@ -400,6 +401,15 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): if field.remote_field.through._meta.auto_created: self.delete_model(field.remote_field.through) # For explicit "through" M2M fields, do nothing + elif ( + self.connection.features.can_alter_table_drop_column + # Primary keys, unique fields, and foreign keys are not + # supported in ALTER TABLE DROP COLUMN. + and not field.primary_key + and not field.unique + and not (field.remote_field and field.db_constraint) + ): + super().remove_field(model, field) # For everything else, remake. else: # It might not actually have a column behind it |