-->

Foreign key support in SQLite3

2019-02-26 07:04发布

问题:

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.

回答1:

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.