gpt4 book ai didi

php - 创建表时出错 : Key column doesn't exist

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

我尝试创建这些表:

$sql = "CREATE TABLE IF NOT EXISTS Articls (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(254) COLLATE utf8_persian_ci NOT NULL
) DEFAULT COLLATE utf8_persian_ci";



$sql = "CREATE TABLE IF NOT EXISTS Tags (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
id_articls INT(10) UNSIGNED NOT NULL,
name VARCHAR(256) COLLATE utf8_persian_ci NOT NULL,
FOREIGN KEY (`Tags.id_articls`) REFERENCES Articls(`Articls.id`)
) DEFAULT COLLATE utf8_persian_ci"

;

第一个表创建成功,但第二个表出现此错误:

Error creating table: Key column 'Tags.id_articls' doesn't exist in table

如果我删除 Tags.Tags.id_articlsTags.id_articls我得到 errno: 150

如果我尝试一下

   $sql = "CREATE TABLE IF NOT EXISTS Tags (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
id_articls INT(10) UNSIGNED NOT NULL,
name VARCHAR(256) COLLATE utf8_persian_ci NOT NULL,
FOREIGN KEY (Tags.id_articls) REFERENCES Articls(Articls.id)
) DEFAULT COLLATE utf8_persian_ci"

我收到此错误:

Error creating table: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.id_articls) REFERENCES Articls(Articls.id) ) DEFAULT COLLATE utf8_persian_ci' at line 5

最佳答案

Tags 表中的外键应该是 id_articls 而不是 Tags.id_articls

关于php - 创建表时出错 : Key column doesn't exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27680602/

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