diff --git a/matemat/db/wrapper.py b/matemat/db/wrapper.py index 30fd6e5..bea257e 100644 --- a/matemat/db/wrapper.py +++ b/matemat/db/wrapper.py @@ -74,10 +74,12 @@ class DatabaseWrapper(object): # Enable foreign key enforcement cursor = self._sqlite_db.cursor() - cursor.execute('PRAGMA foreign_keys = 1') + cursor.execute('PRAGMA foreign_keys=ON') def _upgrade(self, from_version: int, to_version: int) -> None: with self.transaction() as c: + c.execute('PRAGMA foreign_keys=OFF') + c.execute('PRAGMA legacy_alter_table=ON') if from_version <= 1 and to_version >= 2: migrate_schema_1_to_2(c) if from_version <= 2 and to_version >= 3: @@ -98,6 +100,8 @@ class DatabaseWrapper(object): migrate_schema_8_to_9(c) if from_version <= 9 and to_version >= 10: migrate_schema_9_to_10(c) + c.execute('PRAGMA foreign_key_check') + c.execute('PRAGMA foreign_keys=ON') def connect(self) -> None: if self.is_connected():