当我尝试从表“产品”中删除所有内容时,出现标题中的错误消息 SQLite错误1:
外键不匹配-引用“变量”的“股票”
这是我的表定义
CREATE TABLE Products ( Codart TEXT NOT NULL, Descri TEXT NOT NULL,...
CONSTRAINT PK_Products PRIMARY KEY(Codart) )
CREATE TABLE Variants ( Codart TEXT NOT NULL, Codvar TEXT NOT NULL,
CONSTRAINT PK_Variants PRIMARY KEY(Codart, Codvar),
CONSTRAINT FK_Products FOREIGN KEY (Codart) REFERENCES Products(Codart) ON DELETE CASCADE )
CREATE TABLE Stock (Year int not null, Codart text NOT NULL, Codvar text NOT NULL, Qty real NOT NULL,
CONSTRAINT PK_Stock PRIMARY KEY(`Year`,`Codart`,`Codvar`),
CONSTRAINT FK_Products FOREIGN KEY (Codart) REFERENCES Products(Codart) ON DELETE CASCADE,
CONSTRAINT FK_Variants FOREIGN KEY (Codvar) REFERENCES Variants(Codvar) ON DELETE CASCADE )
问题是我何时尝试跑步 “从产品中删除” 我在上面遇到错误
答案 0 :(得分:0)
在Stock
上尝试
CONSTRAINT FK_Variants FOREIGN KEY (Codart,Codvar) REFERENCES Variants(Codart,Codvar) ON DELETE CASCADE