gpt4 book ai didi

MySQL ERROR 1064 (42000) - 即使有反引号

转载 作者:行者123 更新时间:2023-11-29 04:53:21 26 4
gpt4 key购买 nike

我一定遗漏了一些明显的东西,但仍然......

当我尝试运行以下命令时出现 MySQL 错误 1064 (42000):

CREATE TABLE `mgr_user`
(
`id` INT NOT NULL AUTO_INCREMENT,
`customer_id` INT NOT NULL,
`username` VARCHAR(25),
`password` VARCHAR(100),

INDEX(`customer_id`),
FOREIGN KEY `customer_id` REFERENCES `customer`(`id`) ON UPDATE CASCADE ON DELETE RESTRICT
);

最佳答案

您需要用括号将外键名称括起来。此外,您的自动列必须是一个键。见下文

CREATE TABLE `mgr_user`
(
`id` INT NOT NULL AUTO_INCREMENT,
`customer_id` INT NOT NULL,
`username` VARCHAR(25),
`password` VARCHAR(100),
INDEX(`customer_id`),
UNIQUE KEY (`id`), -- <- Auto column is should be a key
FOREIGN KEY (`customer_id`) REFERENCES `customer`(`id`) ON UPDATE CASCADE ON DELETE RESTRICT
);

在这 2 个更改之后,我得到了 Query OK, 0 rows affected (0.07 sec)

关于MySQL ERROR 1064 (42000) - 即使有反引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9197292/

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