gpt4 book ai didi

MySQL建表后无法添加外键约束

转载 作者:行者123 更新时间:2023-11-29 15:35:43 26 4
gpt4 key购买 nike

我不确定以下 MySQL 语句有什么问题。我已经创建了每个表,但是在运行以下语句时出现错误:

Error Code: 1215. Cannot add foreign key constraint

MySQL 语句:

/**
CREATE TABLE Episodes (
season INT,
num INT,
title VARCHAR(50),
director VARCHAR(50),
viewers DECIMAL(2, 1),
PRIMARY KEY (season, num)
);

CREATE TABLE Characters (
name VARCHAR(50),
house VARCHAR(50),
PRIMARY KEY (name)
);
**/
CREATE TABLE Appearances (
name VARCHAR(50),
season VARCHAR(50),
num INT,
PRIMARY KEY (name, season, num),
FOREIGN KEY (name) REFERENCES Characters(name),
FOREIGN KEY (season) REFERENCES Episodes(season)
);

我在这里做错了什么?

最佳答案

愚蠢的错误,我与season的类型不一致。将 season 更改为 INT 类型修复了此错误。

关于MySQL建表后无法添加外键约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58259415/

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