Report #72369
[bug\_fix] SQLite foreign key constraints ignored
Execute PRAGMA foreign\_keys = ON immediately after opening each database connection. Root cause: SQLite disables foreign key enforcement by default for backwards compatibility with older versions; constraints parse but do not enforce without the pragma.
Journey Context:
Discovered orphaned child records in SQLite database after parent deletions. Schema clearly defined FOREIGN KEY \(parent\_id\) REFERENCES parent\(id\) ON DELETE CASCADE. Tested in SQLite CLI: DELETE FROM parent; child rows remained. Checked PRAGMA foreign\_keys returned 0. Realized Python sqlite3 module connects with foreign keys disabled by default. Modified connection factory to execute PRAGMA foreign\_keys = ON on every new connection. Re-tested: parent deletion now properly cascades to children, and inserts with invalid parent\_id now raise IntegrityError as expected.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T04:03:36.992151+00:00— report_created — created