MySQL“外键约束不正确地形成". [英] MySQL "Foreign key constraint is incorretly formed"
本文介绍了MySQL“外键约束不正确地形成".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用此代码时遇到麻烦.
I am having trouble with this code.
CREATE TABLE Reservation (
Movie_Title varchar(255) NOT NULL,
Theatre_No int NOT NULL,
Complex_Name varchar(255) NOT NULL,
Start_Time datetime NOT NULL,
CustomerID int NOT NULL,
Number_of_Tickets int NOT NULL,
PRIMARY KEY (Movie_Title, Theatre_No, Complex_Name, Start_Time, CustomerID),
FOREIGN KEY (Movie_Title) REFERENCES Showings(Movie_Title),
FOREIGN KEY (Theatre_No) REFERENCES Showings(Theatre_No),
FOREIGN KEY (Complex_Name) REFERENCES Showings(Complex_Name),
FOREIGN KEY (Start_Time) REFERENCES Showings(Start_Time), /* this line causes error*/
FOREIGN KEY (CustomerID) REFERENCES Customer(Account_Number)
);
如果我摆脱了这一行,它就可以正常运行.
if i get rid of this line, it runs fine.
FOREIGN KEY (Start_Time) REFERENCES Showings(Start_Time),
所引用的表(显示)如下;
The referenced Table (Showings) is as follows;
CREATE TABLE Showings (
Movie_Title varchar(255) NOT NULL,
Theatre_No int NOT NULL,
Complex_Name varchar(255) NOT NULL,
Start_Time datetime NOT NULL,
Num_Seats int NOT NULL,
PRIMARY KEY (Movie_Title, Theatre_No, Complex_Name, Start_Time),
FOREIGN KEY (Movie_Title) REFERENCES Movie(Title),
FOREIGN KEY (Theatre_No) REFERENCES Theatre(Theatre_No),
FOREIGN KEY (Complex_Name) REFERENCES Theatre(Complex_Name)
);
我正在使用MariaDB 10.1.3
I am using MariaDB 10.1.3
对不起,如果最终这是一个愚蠢的错误,我对SQL还是很陌生 请,谢谢.
Sorry, if this ends up being a silly mistake, i am fairly new with SQL Please and thank you.
推荐答案
查看全文