Foreign key enforcement in SQLite
See original GitHub issueForeign keys are disabled by default in SQLite3. It would be nice to have an optional enable_foreign_keys
boolean argument to the SqliteDatabase
constructor. It would have two effects. Suppose db = SqliteDatabase(filename, enable_foreign_keys=True)
. Then
db.foreign_keys is True
; anddb.create_tables
would issue
PRAGMA foreign_keys = ON;
Issuing that PRAGMA
in the middle of a multi-statement transaction has no effect and swallows the error. It is only possible to turn on foreign_keys
in SQLite versions greater than 3.6.19 when SQLite is compiled with SQLITE_OMIT_TRIGGER
and SQLITE_OMIT_FOREIGN_KEY
turned off. The versions of SQLite compiled into Python versions 2.7.9 and 3.4.3 on Windows appear to support foreign_keys
.
Issue Analytics
- State:
- Created 9 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
SQLite Foreign Key Support
SQL foreign key constraints are used to enforce "exists" relationships between tables. For example, consider a database schema created using the ...
Read more >SQLite Foreign Key: Enforce Relationships Between Tables
This tutorial shows you how to use the SQLite foreign key constraint to enforce the relationships between correlated tables.
Read more >sqlite - Foreign key isn't being enforced - Stack Overflow
Assuming the library is compiled with foreign key constraints enabled, it must still be enabled by the application at runtime, using the PRAGMA ......
Read more >Primary Key and Foreign Key in SQLite with Examples - Guru99
The SQLite foreign key is a constraint that verifies the existence of value present in one table to another table that has a...
Read more >How to Enable Foreign Key Support in SQLite - Database.Guide
Enable Foreign Keys at Runtime ... Even when the library has been compiled with foreign key constraints enabled, you still need to enable...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
SqliteDatabase can now be instantiated with pragmas, so:
This has performance implications. Hence, we use the default SQLite behavior but allow you to use auto-increment if you really want that. http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PrimaryKeyAutoIncrementField