문제

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) 
도움이 되었습니까?

해결책

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.

다른 팁

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top