2

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.

Kah
  • 627
  • 2
  • 11
  • 28
  • possible duplicate of [Error 1022 - Can't write; duplicate key in table](http://stackoverflow.com/questions/18056786/error-1022-cant-write-duplicate-key-in-table) – JuniorCompressor Mar 20 '15 at 16:36

1 Answers1

1

Try renaming your constraints, they are probably duplicated somewhere in your database.

Example :

fk_cl becomes fk_course_catalog_cl
fk_dm become  fk_course_catalog_dm

Or w/e alternative name you want it to be.

Jean-François Savard
  • 20,626
  • 7
  • 49
  • 76