SQLite foreign keys not enforced: PRAGMA foreign_keys is OFF by default
Child rows can reference missing parents, and ON DELETE CASCADE doesn't run, because foreign key enforcement is disabled per connection.
SQLite foreign keys not enforcedPRAGMA foreign_keys OFF by defaultON DELETE CASCADE not working SQLiteforeign key constraint is ignored SQLitePRAGMA foreign_key_check Meaning
Run PRAGMA foreign_keys = ON; on every new connection (it's off by default in SQLite, and can't be changed inside a transaction). Many ORMs/drivers offer a connection option. After enabling, PRAGMA foreign_key_check; finds existing violations.
Common causes
- PRAGMA never enabled
- Enabled on one connection only (pool)
- Executed inside a transaction (ignored)
- Old rows already violating FKs
- Using an ORM that doesn't set it
⚡ Quick fix
- Execute
PRAGMA foreign_keys = ON;on every connection - Run
PRAGMA foreign_key_check;to find violations - Enable it in the driver's connect hook
Detailed fix by platform
SQL
- sql
PRAGMA foreign_keys = ON; PRAGMA foreign_key_check;
How to diagnose
- PRAGMA — ON for this connection?
- Pool — Sets it per connection?
- Violations — Existing?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in SQL
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 18 Nov 2026