ERROR 1005(HY000):无法创建表 'test.sports'(错误:150)
问题描述:
ERROR 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;
答
你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;
只是另一个机器人.. – NachoB
你可以发布'records'表的结构吗? –
+ ------------ + ------------- + ------ + ----- + -------- - + ------- + |字段|类型|空| Key |默认|额外| + ------------ + ------------- + ------ + ----- + -------- - + ------- + | student_id | int(11)| NO | PRI | 0 | | |主题|文字|是| | NULL | | |标记| int(11)|是| | NULL | | |老师| varchar(20)|是| | NULL | | |性别| tinytext |是| | NULL | | |年龄| int(11)|是| | NULL | | + ------------ + ------------- + ------ + ----- + -------- - + – deka4tech