2014-09-27 79 views
0

我已經創建表電影和位置,但我似乎得到一個奇怪的錯誤我想知道如果任何人都可以趕上我在這裏做錯了。SQL錯誤創建表

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 Code: 1005. Can't create table 'galaxy.showtimes' (errno: 150) 0.078 sec

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'); 
+0

可能的重複:http://stackoverflow.com/questions/4061293/mysql-cant-create-table-errno-150 – 2014-09-27 01:53:49

回答

1

簡單的錯誤:看看你的第一個外鍵。您正在引用表格ShowTimes。嘗試刪除它。

+0

+1爲了澄清,問題是該鍵被指定爲外鍵,但指的是要添加的表格。這是循環的。 – 2014-09-27 02:12:33