我已经设置了两个表:
CREATE TABLE A
(
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
name TEXT
);
CREATE TABLE B
(
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
id2 INTEGER,
book TEXT,
FOREIGN KEY(id2) REFERENCES A(id)
);
在我插入数据后A
,它看起来像这样:
1 John
2 Amy
3 Peter
在我插入数据后B
,它看起来像这样:
1 1 Lord of the Rings
2 1 Catch 22
3 2 Sum of All Fears
4 3 Hunt for Red October
然后我执行以下语句:
delete from a where id=1;
我得到以下信息:"Error: foreign key constraint failed"
然后我重新启动并重sqlite3
试,但这次我先输入:
PRAGMA foreign_keys = 1;
它仍然不起作用......