gpt4 book ai didi

MySQL:无法创建表(errno = 150)

转载 作者:行者123 更新时间:2023-11-29 08:09:18 27 4
gpt4 key购买 nike

我正在尝试创建 SEASON 和 PLAYER 表,如下所示:

CREATE TABLE SEASON(
season_id INT NOT NULL, #primary key can't be NULL
start_date DATE,
end_date DATE)
ENGINE = INNODB;

CREATE TABLE PLAYER(
player_id INT NOT NULL,
first_name VARCHAR(15) NOT NULL,
last_name VARCHAR(15) NOT NULL,
position VARCHAR(15),
first_season_id INT,
last_season_id INT,
height_feet INT,
height_inch INT,
weight INT,
college VARCHAR(30),
birthday DATE,
PRIMARY KEY(player_id),
FOREIGN KEY(first_season_id) REFERENCES SEASON(season_id)
ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(last_season_id) REFERENCES SEASON(season_id)
ON DELETE CASCADE ON UPDATE CASCADE,
CHECK (height_feet > 0 AND height_inch >= 0 AND weight > 0))
ENGINE=INNODB;

我遇到错误,无法创建 PLAYER 表,但我真的不明白为什么:(

最佳答案

试试这个:

CREATE TABLE SEASON( season_id INT NOT NULL, start_date DATE, end_date DATE, PRIMARY KEY(season_id)) ENGINE = INNODB;

CREATE TABLE PLAYER( player_id INT NOT NULL, first_name VARCHAR(15) NOT NULL, last_name VARCHAR(15) NOT NULL, position VARCHAR(15), first_season_id INT, last_season_id INT, height_feet INT, height_inch INT, weight INT, college VARCHAR(30), birthday DATE, PRIMARY KEY(player_id), FOREIGN KEY(first_season_id) REFERENCES SEASON(season_id) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY(last_season_id) REFERENCES SEASON(season_id) ON DELETE CASCADE ON UPDATE CASCADE, CHECK (height_feet > 0 AND height_inch >= 0 AND weight > 0)) ENGINE=INNODB;

它将 season_id 添加为主键。

关于MySQL:无法创建表(errno = 150),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21960901/

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