【发布时间】:2020-02-20 00:29:43
【问题描述】:
这是我的 sqlite 代码..
CREATE TABLE "performance" (
"title" TEXT,
"date" date,
"theaterID" INTEGER,
PRIMARY KEY("title","date","theaterID"),
FOREIGN KEY("title") REFERENCES "movies"("title"),
FOREIGN KEY("theaterID") REFERENCES "theater"("theaterID")
);
CREATE TABLE "reservation" (
"userName" TEXT,
"reservationID" INTEGER auto_increment,
"date" date,
"theaterID" INTEGER,
PRIMARY KEY("userName","reservationID","date","theaterID"),
FOREIGN KEY("date") REFERENCES "performance"("date"),
FOREIGN KEY("userName") REFERENCES "user"("userName"),
FOREIGN KEY("theaterID") REFERENCES "theater"("theaterID")
);
我按特定顺序进行以下插入:
INSERT INTO performance(title,date,theaterID)
VALUES("The Godfather", 20200230, 9);
INSERT INTO reservation(userName,reservationID,date,theaterID)
VALUES("user1", 1 , 20200230, 9);
在我尝试插入预订之前,一切正常。我收到以下错误:
“外键不匹配错误 - 'reservation' 引用 'performance'”
我似乎找不到原因?我需要做哪些改变?
【问题讨论】:
-
我已经坐在这里几个小时无法找到解决方案.. 非常感谢您的回答
标签: sql database sqlite foreign-keys