summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2018-12-06 11:37:43 -0500
committerTim Graham <timograham@gmail.com>2018-12-07 14:22:42 -0500
commit53b17d4734f06372b66e3ac4db7a1740c503b330 (patch)
treecdc57f1b40d69561f7a2ac1731fe67c1b5f9eb37
parent13501d162f4b243f20e2a89e0799ceb796ea9756 (diff)
downloaddjango-53b17d4734f06372b66e3ac4db7a1740c503b330.tar.gz
[2.0.x] Fixed #29182 -- Fixed schema table alteration on SQLite 3.26+.
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 c8ffdbe514b55ff5c9a2b8cb8bbdf2d3978c188f from master.
-rw-r--r--django/db/backends/sqlite3/schema.py2
-rw-r--r--docs/releases/2.0.10.txt4
2 files changed, 6 insertions, 0 deletions
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py
index add05843c3..bd2278b83b 100644
--- a/django/db/backends/sqlite3/schema.py
+++ b/django/db/backends/sqlite3/schema.py
@@ -22,10 +22,12 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
# 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):
diff --git a/docs/releases/2.0.10.txt b/docs/releases/2.0.10.txt
index fd2e7f5ebf..ece2521867 100644
--- a/docs/releases/2.0.10.txt
+++ b/docs/releases/2.0.10.txt
@@ -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`).