Why aren't my sqlite3 foreign keys working?

我的未来我决定 提交于 2019-11-30 20:08:30

Working foreign key support in SQLite is very new -- it was only released in 3.6.19 on October 14th. Are you sure you're using SQLite 3.6.19 or later?

Check the sqlite_version constant in the sqlite3 module. E.g. on a Mac OS X 10.6 system with the default python/sqlite install:

>>> import sqlite3
>>> sqlite3.sqlite_version
'3.6.12'
>>> 

As said by Nicholas, check if your version of sqlite has foreign key support. This doesn't matter if the version of sqlite greater than or equal to 3.6.19. The source may be compiled with foreign key support turned off. To check execute the following command.

cursor.execute("PRAGMA foreign_keys")

If it does not return any data then your version has no foreign key support.

NB: Foreign key support is not enforced in sqlite3 as of now. Check out here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!