Report #89011
[bug\_fix] Foreign key constraints not enforced / orphaned records \(SQLite\)
Execute PRAGMA foreign\_keys = ON; on every database connection immediately after opening it. This setting is not persistent and defaults to OFF for backward compatibility.
Journey Context:
Built an iOS app using Core Data with SQLite backend. Noticed that deleting a parent object left orphaned child records in the database, breaking referential integrity. Checked schema, confirmed FOREIGN KEY constraints were defined in CREATE TABLE. Spent hours debugging ORM before realizing SQLite PRAGMA foreign\_keys returned 0. Added PRAGMA foreign\_keys = ON; to the database initialization code, immediately causing deletions to cascade properly or throw constraint violations as expected.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:59:28.460841+00:00— report_created — created