Skip to content

fix(sqlite): enforce foreign key constraints on connect - #66

Merged
benkhalife merged 1 commit into
mainfrom
fix/sqlite-foreign-key-enforcement
Aug 4, 2026
Merged

fix(sqlite): enforce foreign key constraints on connect#66
benkhalife merged 1 commit into
mainfrom
fix/sqlite-foreign-key-enforcement

Conversation

@benkhalife

Copy link
Copy Markdown
Member

SQLite ignores FOREIGN KEY constraints unless a connection issues PRAGMA foreign_keys = ON; this library never did, so FK violations were silently accepted on SQLite regardless of schema definitions.

Fix: enable the pragma in Connection::createPdo() for every SQLite connection. Also drops the SQLite skip in
SchemaForeignKeyTest::testCreateWithForeignKeyActuallyEnforcesTheConstraint, now that it passes on all drivers.

Adds tests/Integration/SqliteForeignKeyPragmaTest.php; reproduced against the pre-fix code (pragma read back as 0, orphan inserts succeeded) and verified fixed. Full unit + integration suites pass on both MySQL and SQLite with no regressions.

SQLite ignores FOREIGN KEY constraints unless a connection issues
PRAGMA foreign_keys = ON; this library never did, so FK violations
were silently accepted on SQLite regardless of schema definitions.

Fix: enable the pragma in Connection::createPdo() for every SQLite
connection. Also drops the SQLite skip in
SchemaForeignKeyTest::testCreateWithForeignKeyActuallyEnforcesTheConstraint,
now that it passes on all drivers.

Adds tests/Integration/SqliteForeignKeyPragmaTest.php; reproduced
against the pre-fix code (pragma read back as 0, orphan inserts
succeeded) and verified fixed. Full unit + integration suites pass
on both MySQL and SQLite with no regressions.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@benkhalife
benkhalife merged commit ca7fda7 into main Aug 4, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant