SQLite 外键无法正常工作

标签 sqlite foreign-keys sqlitemanager

<分区>

以下是创建表的查询:

CREATE TABLE "FacilityRating"(
    "FacilityRatingId" INTEGER PRIMARY KEY NOT NULL,
    "Stars" VARCHAR,
    "Facility_FacilityId" INTEGER,
    "User_UserId" INTEGER,
    FOREIGN KEY (Facility_FacilityId)
        REFERENCES Facility(FacilityId)
        ON DELETE CASCADE
        ON UPDATE CASCADE,
    FOREIGN KEY (User_UserId)
        REFERENCES User(UserId)
        ON DELETE CASCADE
        ON UPDATE CASCADE
)

但是,当我在 Facility_FacilityIdUser_UserId 中插入一个带有一些随机数的新行时,SQLite 不会给出错误,但无论如何都会添加它。

这是一个快照:

enter image description here

有什么提示吗?我正在使用 SQLite Manager,它是 Mozilla Firefox 的附加组件

最佳答案

documentation说:

Foreign key constraints must be enabled by the application at runtime, using the PRAGMA foreign_keys command. For example:

sqlite> PRAGMA foreign_keys = ON;

Foreign key constraints are disabled by default (for backwards compatibility), so must be enabled separately for each database connection.

关于SQLite 外键无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23767059/

相关文章:

MySQL 添加外键到现有表 PHP

mysql - 1 :1 relation 中的双向外键约束

sqlite - 外键约束不起作用

sql - 如何对SQLITE数据库中的表列重新排序?

c - 我无法让 Eclipse MinGW 和 Sqlite 一起使用 C 程序

sqlite - 在 Swift 中访问 SQLite 数据库

c# - SQLite 错误 : The 'DbProviderFactories' section can only appear once per config file (IBM Client Access)

iOS Sqlite3 SQLITE_ERROR