MySQL table 中的重复键
MySQL duplicate key in table
我在以下 SQL 查询中遇到错误,我不确定如何修复它。错误信息是:
"Error Code: 1022. Can't write; duplicate key in table
't_course_catalog'"
这里是查询:
CREATE TABLE IF NOT EXISTS `TrainingPlan`.`T_Course_Catalog` (
`CC_ID` INT NOT NULL AUTO_INCREMENT,
`ID_Catalog_Level` INT NOT NULL,
`Catalog_Name` VARCHAR(50) NOT NULL,
`ID_Delivery_Method` INT NOT NULL,
`Created_Date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Created_By` VARCHAR(8) NOT NULL,
`Modified_Date` TIMESTAMP NULL,
`Modified_By` VARCHAR(8) NULL,
`Deleted` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`CC_ID`),
INDEX `fk_cl_idx` (`ID_Catalog_Level` ASC),
INDEX `fk_dm_idx` (`ID_Delivery_Method` ASC),
CONSTRAINT `fk_cl`
FOREIGN KEY (`ID_Catalog_Level`)
REFERENCES `TrainingPlan`.`T_Catalog_Level` (`CL_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_dm`
FOREIGN KEY (`ID_Delivery_Method`)
REFERENCES `TrainingPlan`.`T_Delivery_Method` (`DM_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
引用外键应该没有问题,因为引用 table 存在。
尝试重命名您的约束,它们可能在您的数据库中的某处重复。
示例:
fk_cl becomes fk_course_catalog_cl
fk_dm become fk_course_catalog_dm
或w/e您想要的替代名称。
我在以下 SQL 查询中遇到错误,我不确定如何修复它。错误信息是:
"Error Code: 1022. Can't write; duplicate key in table 't_course_catalog'"
这里是查询:
CREATE TABLE IF NOT EXISTS `TrainingPlan`.`T_Course_Catalog` (
`CC_ID` INT NOT NULL AUTO_INCREMENT,
`ID_Catalog_Level` INT NOT NULL,
`Catalog_Name` VARCHAR(50) NOT NULL,
`ID_Delivery_Method` INT NOT NULL,
`Created_Date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Created_By` VARCHAR(8) NOT NULL,
`Modified_Date` TIMESTAMP NULL,
`Modified_By` VARCHAR(8) NULL,
`Deleted` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`CC_ID`),
INDEX `fk_cl_idx` (`ID_Catalog_Level` ASC),
INDEX `fk_dm_idx` (`ID_Delivery_Method` ASC),
CONSTRAINT `fk_cl`
FOREIGN KEY (`ID_Catalog_Level`)
REFERENCES `TrainingPlan`.`T_Catalog_Level` (`CL_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_dm`
FOREIGN KEY (`ID_Delivery_Method`)
REFERENCES `TrainingPlan`.`T_Delivery_Method` (`DM_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
引用外键应该没有问题,因为引用 table 存在。
尝试重命名您的约束,它们可能在您的数据库中的某处重复。
示例:
fk_cl becomes fk_course_catalog_cl
fk_dm become fk_course_catalog_dm
或w/e您想要的替代名称。