【发布时间】:2016-05-22 15:28:30
【问题描述】:
为什么 Sqlite 允许我在 table2 中插入与 table1 中的任何主键都不匹配的外键? 我正在使用 .NET 和 System.Data.SQLite.dll
这是我的设置:
create table [table1] (
[Id] integer primary key NOT NULL
, [col1] nvarchar(100) NULL
);
create table [table2] (
[Id] integer primary key NOT NULL
, [col2] integer NOT NULL
, FOREIGN KEY(col2) REFERENCES table1(Id)
);
INSERT INTO [table1] ([col1]) VALUES ('val1');
INSERT INTO [table2] ([col2]) VALUES ('2');
【问题讨论】:
-
似乎是重复,尽管我通过在连接字符串中启用外键约束来解决它,如下所示:“Data Source=:memory:;foreign keys=true;”