# SQLite foreign keys not enforced: PRAGMA foreign_keys is OFF by default

**Code:** `PRAGMA foreign_keys` · **Category:** SQL · **Seen on:** SQLite

Child rows can reference missing parents, and ON DELETE CASCADE doesn't run, because foreign key enforcement is disabled per connection.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/sql/sqlite-foreign-keys-not-enforced-pragma)
