Does SQLite support referential integrity?

旧时模样 提交于 2019-12-07 07:44:40

问题


I have a Django web-server configured to use SQLite.

In a many-to-many relationship (with extra fields), Django forces me to use the relationship model to establish a relationship between two objects. But I'm able to create a relationship between objects, that don't yet exist in the related tables.

For e.g:

I have table1 and table2 which are related via table12.
In table1, there is just one object called A.
In table2, there is just one object called X.
I can create a record in table12 that depict a relationship between A & Y; even though Y doesn't exist in table2.

My relationship model has marked the foreign keys appropriately.


回答1:


SQLite does not enforce foreign key constraints by default (mostly to be backward compatible).

To enable it, you have to execute

PRAGMA foreign_keys = 1

after you connected to the database.

See the manual about PRAGMA foreign_keys for more details.



来源:https://stackoverflow.com/questions/17213454/does-sqlite-support-referential-integrity

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