gpt4 book ai didi

mysql - 错误: Error 1022: Can't write; duplicate key in table 'recipes'

转载 作者:行者123 更新时间:2023-11-29 16:06:05 26 4
gpt4 key购买 nike

当我对数据库进行正向设计时,我收到以下错误:

ERROR: Error 1022: Can't write; duplicate key in table 'recipes'

有什么建议吗?

我在 stackoverflow 中研究了这个问题,我想如果我更改其他表中的一些外键名称(其中一些具有相同的外键名称),就不会出现错误。相同的错误代码仍然存在。我的数据库架构仅显示八个表中的 2 个。

在服务器中执行SQL脚本

ERROR: Error 1022: Can't write; duplicate key in table 'recipes'
SQL Code:
-- -----------------------------------------------------
-- Table `our_recipes`.`recipes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `our_recipes`.`recipes` (
`recipe_id` INT NOT NULL,
`chef_id` INT NOT NULL,
`recipe_name` CHAR(25) NULL,
`description` LONGTEXT NULL,
`min_prep` VARCHAR(25) NULL,
`total_time` INT NULL,
`servings_min` VARCHAR(25) NULL,
`servings_max` VARCHAR(45) NULL,
`directions` VARCHAR(45) NULL,
`website_id1` VARCHAR(25) NOT NULL,
PRIMARY KEY (`recipe_id`),
INDEX `chef_id_idx` (`chef_id` ASC),
INDEX `website_id_idx` (`website_id1` ASC),
UNIQUE INDEX `recipe_id_UNIQUE` (`recipe_id` ASC),
CONSTRAINT `chef_id`
FOREIGN KEY (`chef_id`)
REFERENCES `our_recipes`.`chef` (`chef_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `website_id`
FOREIGN KEY (`website_id1`)
REFERENCES `our_recipes`.`website` (`website_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB

我预计数据库模式中有八个表。我也希望不会出现错误。

最佳答案

错误

Error 1022: Can't write; duplicate key in table 'recipes' SQL Code

告诉您,您正在表 recipes 中插入一条记录,该记录的 ID 或唯一标识符已存在于表中。

要解决此问题,请确保插入语句脚本中没有重复的主键。

关于mysql - 错误: Error 1022: Can't write; duplicate key in table 'recipes' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55737810/

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