gpt4 book ai didi

mysql 外键引用语法错误

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

CREATE TABLE comments (
id INT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
body TEXT DEFAULT NULL,
user_id INT(7) UNSIGNED NOT NULL,
PRIMARY KEY (id)
FOREIGN KEY (user_id) REFERENCES user(id)
) AUTO_INCREMENT = 1;

我似乎无法使用 FOREIGN 键来处理此语句。我不断收到错误

ERROR 1064 (42000): You have an error in your SQL syntax; ch eck the manual that corresponds to your MySQL server version for the right syntax to use near 'FOREIGN KEY (user_id) REF ERENCES user(id) ) AUTO_INCREMENT = 1' at line 6

最佳答案

主键后添加逗号:

CREATE TABLE comments (
id INT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
body TEXT DEFAULT NULL,
user_id INT(7) UNSIGNED NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (user_id) REFERENCES user(id)
) AUTO_INCREMENT = 1;

关于mysql 外键引用语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44482274/

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