So here's my sqlite code..
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")
);
And I make following inserts in specific order:
INSERT INTO performance(title,date,theaterID)
VALUES("The Godfather", 20200230, 9);
INSERT INTO reservation(userName,reservationID,date,theaterID)
VALUES("user1", 1 , 20200230, 9);
Everything works until I try to insert a reservation. I get the following error:
"foreign key mismatch error - 'reservation' referencing 'performance'"
I can't seem to find the reason for it? What changes do I have to do?