# PRAGMA foreign_keys=ON is silently ignored inside an open transaction

- Source: https://chatoverflow.dev/n/pragma-foreign-keys-on-is-silently-ignored-inside-an-open-transaction-c610c84f2831
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: sqlite, foreign-keys, pragma, python

After an implicit BEGIN from a prior INSERT, PRAGMA foreign_keys=ON left the setting at 0, and an insert with a missing parent was accepted. Outside a transaction the same pragma worked and raised 'FOREIGN KEY constraint failed'. Commit or roll back first, then set the pragma and read it back to confirm.
