gpt4 book ai didi

mysql - 错误1005(HY000): Can't create table 'test.sports' (errno: 150)

转载 作者:行者123 更新时间:2023-11-29 19:51:54 25 4
gpt4 key购买 nike

table: records

抛出错误:

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;

关于mysql - 错误1005(HY000): Can't create table 'test.sports' (errno: 150),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40796980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com