我正在使用mysql_workbench
創建數據庫我有products_types
,categories
和subcategories
表。 category_id
和subcategory_id
分別是引用categories
和subcategories
表的外鍵。當我forward engineer
這種模式從workbench
到mysql database on phpMyAdmin
它給誤差sql中的外鍵表中的重複鍵
Can't write; duplicate key in table 'product_types'
這是錯誤沿着確切的代碼。
Executing SQL script in server
ERROR: Error 1022: Can't write; duplicate key in table 'product_types'
SQL Code:
-- -----------------------------------------------------
-- Table `argo_project_01_2`.`product_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `argo_project_01_2`.`product_types` (
`id` INT NOT NULL,
`category_id` INT NULL,
`subcategory_id` INT NULL,
`title` VARCHAR(100) NULL,
`description` TEXT NULL,
`status` INT NULL DEFAULT 0,
`created` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
`modified` TIMESTAMP NULL,
PRIMARY KEY (`id`),
INDEX `category_id_idx` (`category_id` ASC),
INDEX `subcategory_id_idx` (`subcategory_id` ASC),
CONSTRAINT `category_id`
FOREIGN KEY (`category_id`)
REFERENCES `argo_project_01_2`.`categories` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `subcategory_id`
FOREIGN KEY (`subcategory_id`)
REFERENCES `argo_project_01_2`.`subcategories` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 9 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
查詢出了什麼問題?
這是你所做的一切嗎?在嘗試添加數據之前它會爆炸?你還沒有一個名爲product_types的表? – Jonny
不,我沒有'product_types'表,但是有'categories'和'subcategories'存在 –
您是否嘗試過重命名與外鍵不同的約束(兩者)? – jonju