Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foreign key support in SQLite3

According to this thread from 2010, an "EnforceFKConstraints" connection string property was supposed to be implemented into future releases of SQLite. Does anyone know if the developers have gotten around to doing that?

If not, is there another way I can enable foreign key support without doing "PRAGMA foreign_keys = ON" on each connection? I need this to make sure that deletes always cascade.

like image 419
rafale Avatar asked Aug 13 '26 07:08

rafale


1 Answers

Future development of System.Data.SQLite ADO.NET provider for SQLite is done by this group. The project is currently in migration status and some features are even unavailable now (which were available in 1.0.66 version, which is last maintained by Robert Simpson (original library author)).

According to latest source code available in trunk "EnforceFKConstraints" is not supported. However there is foreign keys connection string property which have default value of False, maybe it does the job? Try including foreign keys=True property in your connection string. Be sure to use latest stable build from here.

Update. After looking deeper in source, I'm almost sure that this connection string property is doing exactly that you want.

like image 109
Petr Abdulin Avatar answered Aug 16 '26 07:08

Petr Abdulin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!