summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3/schema.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/backends/sqlite3/schema.py')
-rw-r--r--django/db/backends/sqlite3/schema.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py
index e0d8135cbd..0954c66aaf 100644
--- a/django/db/backends/sqlite3/schema.py
+++ b/django/db/backends/sqlite3/schema.py
@@ -19,8 +19,15 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
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()
+ # disabled. Enforce it here for the duration of the schema edition.
+ if not self.connection.disable_constraint_checking():
+ raise NotSupportedError(
+ 'SQLite schema editor cannot be used while foreign key '
+ 'constraint checks are enabled. Make sure to disable them '
+ 'before entering a transaction.atomic() context because '
+ '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__()