Question

When running the following statement:

CREATE  TABLE `intelischool`.`facultyclasses` (
  `id` VARCHAR(45) NOT NULL ,
  `class` VARCHAR(45) NOT NULL ,
  `subject` VARCHAR(45) NOT NULL ,
  `year` VARCHAR(45) NOT NULL ,
  `section` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`id`, `section`, `year`, `subject`, `class`) ,
  INDEX `id` (`id` ASC) ,
  CONSTRAINT `id`
    FOREIGN KEY (`id` )
    REFERENCES `intelischool`.`faculty` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)

I get the error:

ERROR 1005: Can't create table 'intelischool.facultyclasses' (errno: 121) 
Was it helpful?

Solution

This mailing list thread is about the same problem, and the conclusion reached there was that it was caused by a duplicate constraint name.

You probably have another

CONSTRAINT `id`

in another table of the same databse. Those names need to be unique per database. Give it a name like

CONSTRAINT `facultyclasses_foreignkey`

or just delete that line and let the database generate a name for it automatically.

OTHER TIPS

Missing comma before Foreign key defination

otherwise

Dropped the tables and created them with an index (instead of adding an index to an already created tables)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top