【问题标题】:Does SQLite support referential integrity?SQLite 是否支持参照完整性?
【发布时间】:2013-06-17 07:10:23
【问题描述】:

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

在多对多关系(带有额外字段)中,Django 强制我使用关系模型来建立两个对象之间的关系。但我能够在相关表中尚不存在的对象之间创建关系。

例如:

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.

我的关系模型已经适当地标记了外键。

【问题讨论】:

    标签: django django-models sqlite referential-integrity


    【解决方案1】:

    默认情况下,SQLite 不强制执行foreign key constraints(主要是为了向后兼容)。

    要启用它,您必须执行

    PRAGMA foreign_keys = 1
    

    连接到数据库之后。

    详情请参阅PRAGMA foreign_keys 的手册。

    【讨论】:

    猜你喜欢
    • 2010-12-29
    • 1970-01-01
    • 2010-09-26
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 2012-03-19
    • 1970-01-01
    相关资源
    最近更新 更多