← All notes

SQLite foreign keys are off by default

Short answer

SQLite supports foreign key constraints, but enforcement is disabled by default.

PRAGMA foreign_keys = ON;
CREATE TABLE track (
  id INTEGER PRIMARY KEY,
  artist_id INTEGER REFERENCES artist(id) ON DELETE CASCADE
);

Key points

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: SQLite (sqlite.org), SQLite Foreign Key Support, Public domain (sqlite.org); SQLite (sqlite.org), CREATE TABLE, Public domain (sqlite.org).

Cite this

Permanent ID: iil:note:405h0pf4

iinventedlight. 2026. "SQLite foreign keys are off by default." iinventedlight Library, iil:note:405h0pf4, version of 2026-11-04. https://iinventedlight.com/library/notes/sqlite-foreign-keys/. License: CC-BY-4.0.

@misc{iil_note_405h0pf4,
  author = {{iinventedlight}},
  title = {{SQLite foreign keys are off by default}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/sqlite-foreign-keys/},
  note = {Permanent ID iil:note:405h0pf4. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/sqlite-foreign-keys.md.