SQLite3 中的删除级联
我有以下结构:(抱歉,名字很尴尬,因为它是我的 iPhone 应用程序的 SQLite 数据库,尚未发布)
CREATE TABLE klb_log (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
log_comment varchar(512)
)
CREATE TABLE klb_log_food_maps (
uid integer,
did integer,
PRIMARY KEY (uid,did),
FOREIGN KEY (uid) references klb_log(id) ON DELETE CASCADE,
FOREIGN KEY (did) references klb_food(id) ON DELETE CASCADE
)
CREATE TABLE klb_food (
id integer,
description varchar(255),
PRIMARY KEY (id)
)
是否有原因导致 klb_log_food_maps
中的行在以下情况下未被删除我删除 klb_log
中的一行?
I have the following structure: (Sorry for awkward names, it is because it is a sqlite database for my iPhone app which is not released yet)
CREATE TABLE klb_log (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
log_comment varchar(512)
)
CREATE TABLE klb_log_food_maps (
uid integer,
did integer,
PRIMARY KEY (uid,did),
FOREIGN KEY (uid) references klb_log(id) ON DELETE CASCADE,
FOREIGN KEY (did) references klb_food(id) ON DELETE CASCADE
)
CREATE TABLE klb_food (
id integer,
description varchar(255),
PRIMARY KEY (id)
)
Is there a reason why the row in klb_log_food_maps
is not removed when I delete a row in klb_log
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,SQLite 中未启用外键支持。每次使用 pragma 连接到数据库时,您都需要手动启用它:
Foreign key support is not enabled in SQLite by default. You need to enable it manually each time you connect to the database using the pragma:
您启用了外键支持吗?
查询
PRAGMAforeign_keys = ON;
将其打开Do you have foreign key support enabled?
query
PRAGMA foreign_keys = ON;
to turn it on