From 7a05b8a2fac57e32a61726893d4601352c1d1c8d Mon Sep 17 00:00:00 2001 From: Aaron Linville Date: Thu, 17 Aug 2023 18:06:25 -0400 Subject: Fixed #24018 -- Allowed setting pragma options on SQLite. --- django/db/backends/sqlite3/base.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'django/db/backends/sqlite3/base.py') diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 8e17ea3d44..c7cf947800 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -187,6 +187,9 @@ class DatabaseWrapper(BaseDatabaseWrapper): f"{allowed_transaction_modes}, or None." ) self.transaction_mode = transaction_mode.upper() if transaction_mode else None + + init_command = kwargs.pop("init_command", "") + self.init_commands = init_command.split(";") return kwargs def get_database_version(self): @@ -201,6 +204,9 @@ class DatabaseWrapper(BaseDatabaseWrapper): # The macOS bundled SQLite defaults legacy_alter_table ON, which # prevents atomic table renames. conn.execute("PRAGMA legacy_alter_table = OFF") + for init_command in self.init_commands: + if init_command := init_command.strip(): + conn.execute(init_command) return conn def create_cursor(self, name=None): -- cgit v1.3