简体   繁体   English

SQL错误创建表

[英]Sql Error Creating table

I have created tables Movies and Location but i seem to be getting a strange error I was wondering if anyone could catch what I'm doing wrong here. 我已经创建了电影和位置表,但是我似乎遇到了一个奇怪的错误,我想知道是否有人可以在这里找到我做错的事情。

CREATE TABLE ShowTimes
(
   showId int NOT NULL, 
   movieid int NOT NULL,        
   cinemaID int NOT NULL,
   showDate date,
   showTime time,

   PRIMARY KEY (showId),
   FOREIGN KEY ShowTimes (movieid) REFERENCES Movies (movieId),
   FOREIGN KEY (cinemaID) REFERENCES Location (cinemaId)
)

Error: 错误:

Error Code: 1005. Can't create table 'galaxy.showtimes' (errno: 150) 0.078 sec 错误代码:1005。无法创建表'galaxy.showtimes'(errno:150)0.078秒

CREATE TABLE ShowTimes
(
   showId int NOT NULL, 
   movieid int NOT NULL, 
   cinemaID int NOT NULL,
   showDate date,
   showTime time,
   PRIMARY KEY (showId),
   FOREIGN KEY (movieid) REFERENCES Movies (movieId),
   FOREIGN KEY (cinemaID) REFERENCES Location (cinemaId)
);

INSERT INTO ShowTimes VALUES (1, 1, 1, '2013-09-20', '17:00:00'),
                             (2, 1, 1, '2013-09-20', '19:00:00'),
                             (3, 3, 4, '2013-09-20', '17:00:00'),
                             (4, 2, 3, '2013-09-20', '15:15:00');

Simple mistake: look at your first FOREIGN KEY. 一个简单的错误:看看您的第一个外键。 You are referencing the table ShowTimes. 您正在引用表ShowTimes。 Try removing it. 尝试将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM