Skip to content

Commit

Permalink
[2.0.x] Fixed #29182 -- Fixed schema table alteration on SQLite 3.26+.
Browse files Browse the repository at this point in the history
SQLite 3.26 repoints foreign key constraints on table renames even when
foreign_keys pragma is off which breaks every operation that requires
a table rebuild to simulate unsupported ALTER TABLE statements.

The newly introduced legacy_alter_table pragma disables this behavior
and restores the previous schema editor assumptions.

Thanks Florian Apolloner, Christoph Trassl, Chris Lamb for the report and
troubleshooting assistance.

Backport of c8ffdbe from master.
  • Loading branch information
charettes authored and timgraham committed Dec 7, 2018
1 parent 13501d1 commit 53b17d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions django/db/backends/sqlite3/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ def __enter__(self):
# Some SQLite schema alterations need foreign key constraints to be
# disabled. Enforce it here for the duration of the transaction.
self.connection.disable_constraint_checking()
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.cursor().execute('PRAGMA legacy_alter_table = OFF')
self.connection.enable_constraint_checking()

def quote_value(self, value):
Expand Down
4 changes: 4 additions & 0 deletions docs/releases/2.0.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ Bugfixes
* Prevented repetitive calls to ``geos_version_tuple()`` in the ``WKBWriter``
class in an attempt to fix a random crash involving ``LooseVersion`` since
Django 2.0.6 (:ticket:`29959`).

* Fixed a schema corruption issue on SQLite 3.26+. You might have to drop and
rebuild your SQLite database if you applied a migration while using an older
version of Django with SQLite 3.26 or later (:ticket:`29182`).

0 comments on commit 53b17d4

Please sign in to comment.