diff options
| author | Simon Charette <charette.s@gmail.com> | 2018-12-11 03:06:24 -0500 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2018-12-17 10:44:05 +0100 |
| commit | 894cb13779e6d092974c873bd2cf1452554d2e06 (patch) | |
| tree | afebfdae496f68695b36db17af90f0bbbe902f3d /django/db/backends/sqlite3/schema.py | |
| parent | 7289874adceec46b5367ec3157cdd10c711253a0 (diff) | |
Refs #29182 -- Stopped relying on legacy alter table semantic on SQLite 3.26+.
SQLite 3.26 changed the behavior of table and column renaming operations to
repoint foreign key references even if foreign key checks are disabled.
This makes the workarounds in place to simulate this behavior unnecessary on
SQLite 3.26+. Refs #30033.
Diffstat (limited to 'django/db/backends/sqlite3/schema.py')
| -rw-r--r-- | django/db/backends/sqlite3/schema.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py index 7c3648cff2..3992d86651 100644 --- a/django/db/backends/sqlite3/schema.py +++ b/django/db/backends/sqlite3/schema.py @@ -27,13 +27,11 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): 'SQLite3 does not support disabling them in the middle of ' 'a multi-statement transaction.' ) - self.connection.cursor().execute('PRAGMA legacy_alter_table = ON') return super().__enter__() def __exit__(self, exc_type, exc_value, traceback): super().__exit__(exc_type, exc_value, traceback) self.connection.check_constraints() - self.connection.cursor().execute('PRAGMA legacy_alter_table = OFF') self.connection.enable_constraint_checking() def quote_value(self, value): @@ -84,11 +82,12 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): return False def alter_db_table(self, model, old_db_table, new_db_table, disable_constraints=True): - if disable_constraints and self._is_referenced_by_fk_constraint(old_db_table): + if (not self.connection.features.supports_atomic_references_rename and + disable_constraints and self._is_referenced_by_fk_constraint(old_db_table)): if self.connection.in_atomic_block: raise NotSupportedError(( 'Renaming the %r table while in a transaction is not ' - 'supported on SQLite because it would break referential ' + 'supported on SQLite < 3.26 because it would break referential ' 'integrity. Try adding `atomic = False` to the Migration class.' ) % old_db_table) self.connection.enable_constraint_checking() @@ -102,11 +101,12 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): table_name = model._meta.db_table _, old_column_name = old_field.get_attname_column() if (new_field.name != old_field_name and + not self.connection.features.supports_atomic_references_rename and self._is_referenced_by_fk_constraint(table_name, old_column_name, ignore_self=True)): if self.connection.in_atomic_block: raise NotSupportedError(( 'Renaming the %r.%r column while in a transaction is not ' - 'supported on SQLite because it would break referential ' + 'supported on SQLite < 3.26 because it would break referential ' 'integrity. Try adding `atomic = False` to the Migration class.' ) % (model._meta.db_table, old_field_name)) with atomic(self.connection.alias): |
