Fixed #31765 -- Enforced enhanced ALTER TABLE behavior for SQLite connections.

This commit is contained in:
Adam Johnson 2021-12-07 11:32:05 +00:00 committed by GitHub
parent adef3d975e
commit 063cf98d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 5 deletions

View File

@ -259,6 +259,9 @@ class DatabaseWrapper(BaseDatabaseWrapper):
conn.create_aggregate('VAR_POP', 1, list_aggregate(statistics.pvariance))
conn.create_aggregate('VAR_SAMP', 1, list_aggregate(statistics.variance))
conn.execute('PRAGMA foreign_keys = ON')
# The macOS bundled SQLite defaults legacy_alter_table ON, which
# prevents atomic table renames (feature supports_atomic_references_rename)
conn.execute('PRAGMA legacy_alter_table = OFF')
return conn
def init_connection_state(self):

View File

@ -1,5 +1,4 @@
import operator
import platform
from django.db import transaction
from django.db.backends.base.features import BaseDatabaseFeatures
@ -91,10 +90,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
@cached_property
def supports_atomic_references_rename(self):
# SQLite 3.28.0 bundled with MacOS 10.15 does not support renaming
# references atomically.
if platform.mac_ver()[0].startswith('10.15.') and Database.sqlite_version_info == (3, 28, 0):
return False
return Database.sqlite_version_info >= (3, 26, 0)
@cached_property