我必须遗漏一些明显的东西,但仍然......
当我尝试运行以下内容时,我收到MySQL ERROR 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
);
答案 0 :(得分:4)
您需要用括号包装外键名称。您的自动列也必须是密钥。见下文
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
);
经过这两次更改后,我得到了Query OK, 0 rows affected (0.07 sec)