参考:
http://sqlite.org/foreignkeys.html
Foreign key constraints are disabled by default (for backwards compatibility),so must be enabled separately for eachdatabase connection. (Note,however,that future releases of sqlite might change so that foreign key constraints enabled by default. Careful developers will not make any assumptions about whether or not foreign keys are enabled by default but will instead enable or disable them as necessary.) The application can also use aPRAGMA foreign_keysstatement to determine if foreign keys are currently enabled. The following command-line session demonstrates this:
sqlite> PRAGMA foreign_keys; 0 sqlite> PRAGMA foreign_keys = ON; sqlite> PRAGMA foreign_keys; 1 sqlite> PRAGMA foreign_keys = OFF; sqlite> PRAGMA foreign_keys; 0 |
Tip: If the command "PRAGMA foreign_keys" returns no data instead of a single row containing "0" or "1",then the version of sqlite you are using does not support foreign keys (either because it is older than 3.6.19 or because it was compiled withSQLITE_OMIT_FOREIGN_KEYorSQLITE_OMIT_TRIGGERdefined).
It is not possible to enable or disable foreign key constraints in the middle of amulti-statement transaction(when sqlite is not inautocommit mode). Attempting to do so does not return an error; it simply has no effect.
原文链接:https://www.f2er.com/sqlite/199832.html