PRAGMA foreign_keys SQL Origin: Data OSI layer 7 · Application Last updated 18 Nov 2026

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.

Exact message you may see SQLite foreign keys not enforcedPRAGMA foreign_keys OFF by defaultON DELETE CASCADE not working SQLiteforeign key constraint is ignored SQLitePRAGMA foreign_key_check
Seen on: SQLite

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

  1. Execute PRAGMA foreign_keys = ON; on every connection
  2. Run PRAGMA foreign_key_check; to find violations
  3. Enable it in the driver's connect hook

Detailed fix by platform

SQL

  1. sql
    PRAGMA foreign_keys = ON;
    PRAGMA foreign_key_check;

How to diagnose

  1. PRAGMA — ON for this connection?
  2. Pool — Sets it per connection?
  3. 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:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

3726 — SQL Server Msg 3726: Could not drop object because it is referenced by a FOREIGN KEY constraint (SQL)3726foreign key order — Foreign key violation caused by insert order or circular references (SQL)foreign key orderORA-02291 — ORA-02291: integrity constraint (SCHEMA.FK_NAME) violated - parent key not found (SQL)ORA-02291ORA-02292 — ORA-02292: integrity constraint (SCHEMA.FK_NAME) violated - child record found (SQL)ORA-02292readonly database — sqlite3.OperationalError: attempt to write a readonly database (SQL)readonly databaseSQLite FK failed — sqlite3.IntegrityError: FOREIGN KEY constraint failed (SQL)SQLite FK failedtransaction — SQLite: cannot start a transaction within a transaction (SQL)transactionPRAGMA fo…

Explore the map of this error Full error map →

🧠 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.