Report #44705
[bug\_fix] SQLite foreign key constraints not enforced despite schema definition
Execute PRAGMA foreign\_keys = ON; immediately after opening every database connection, as foreign key enforcement is disabled by default for backwards compatibility.
Journey Context:
Developer designs SQLite schema with FOREIGN KEY constraints to maintain referential integrity between Orders and Customers tables. Unit tests pass \(single connection, explicit transaction\). Production deployment uses connection pooling \(multiple connections\). Weeks later, data analysis reveals orphaned Order records with non-existent Customer IDs. Investigation shows that while SQLite parses foreign key syntax in CREATE TABLE, it does not enforce them unless PRAGMA foreign\_keys is enabled per connection. Developer adds connection initialization code to execute the pragma, and implements a data cleanup migration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T05:30:16.815973+00:00— report_created — created