I have an error with the following SQL query and I'm not sure how to fix it. The error message is:
"Error Code: 1022. Can't write; duplicate key in table 't_course_catalog'"
Here is the query:
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
It should be no problem to reference the foreign keys because the reference table exists.