Koskamo

Foreign key enforcement pragma

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

SQLite has supported SQL foreign key constraints since version 3.6.19, but enforcement is disabled by default for backwards compatibility: every database connection must enable it at runtime with PRAGMA foreign_keys = ON, separately for each connection. The library must be compiled with neither SQLITE_OMIT_FOREIGN_KEY nor SQLITE_OMIT_TRIGGER defined; with OMIT_TRIGGER defined, foreign key definitions are parsed and queryable via PRAGMA foreign_key_list but not enforced, and PRAGMA foreign_keys is a no-op in that configuration, while OMIT_FOREIGN_KEY makes the definitions a syntax error. Future releases might enable enforcement by default, so careful developers will not assume the current default holds. Supported features include composite foreign key constraints, deferred constraints, and ON DELETE and ON UPDATE actions. Because the pragma is per-connection, enable it on every pooled connection or driver checkout rather than once at startup (Koskamo editorial guidance). Scope: SQLite. Reviewed October 4, 2026.

Source and provenance

Original source
sqlite.org
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.