2016-11-25 70 views
0

table: recordsERROR 1005(HY000):無法創建表 'test.sports'(錯誤:150)

它拋出錯誤:

ERROR 1005 (HY000): Can't create table 'test.sports' (errno: 150).

我需要解決它的幫助。

CREATE TABLE sports(
-> interest text, 
-> prize_money int, 
-> sp_id int NOT NULL, 
-> CONSTRAINT fk_sports 
-> FOREIGN KEY(sp_id) 
-> REFERENCES records(id) 
-> ON DELETE CASCADE 
-> ON UPDATE CASCADE 
->) ENGINE=INNODB; 
+0

只是另一個機器人.. – NachoB

+0

你可以發佈'records'表的結構嗎? –

+0

+ ------------ + ------------- + ------ + ----- + -------- - + ------- + |字段|類型|空| Key |默認|額外| + ------------ + ------------- + ------ + ----- + -------- - + ------- + | student_id | int(11)| NO | PRI | 0 | | |主題|文字|是| | NULL | | |標記| int(11)|是| | NULL | | |老師| varchar(20)|是| | NULL | | |性別| tinytext |是| | NULL | | |年齡| int(11)|是| | NULL | | + ------------ + ------------- + ------ + ----- + -------- - + – deka4tech

回答

0

records表沒有一個叫id列。相反,它的主鍵列是student_id,所以你可能打算從sports的外鍵引用它。試試這個定義:

CREATE TABLE sports(
    interest text, 
    prize_money int, 
    sp_id int NOT NULL, 
    CONSTRAINT fk_sports 
    FOREIGN KEY(sp_id) 
    REFERENCES records(student_id) 
    ON DELETE CASCADE 
    ON UPDATE CASCADE 
) ENGINE=INNODB; 
相關問題