SQLite是否支持引用完整性

SQLite是否支持引用完整性

本文介绍了SQLite是否支持引用完整性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个配置为使用SQLite的Django网络服务器。



在多对多关系(带有额外的字段)中,Django强制我使用关系模型建立两个对象之间的关系。但是我可以创建对象之间的关系,这些关系在相关表格中还不存在。



例如:

 我有table1和table2通过table12相关。 
在表1中,只有一个对象叫做A.
在表2中,只有一个对象叫做X.
我可以在table12中创建一个描述A& Ÿ;即使在表2中不存在Y。

我的关系模型已正确标记了外键。

解决方案

SQLite默认不执行(主要是向后



要启用它,您必须执行

 连接到数据库后,PRAGMA foreign_keys = 1 


有关更多信息,请参阅有关的手册细节。


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.

解决方案

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.

这篇关于SQLite是否支持引用完整性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:03