ERROR 1005(HY000):无法创建表格

时间:2013-10-06 09:59:05

标签: mysql foreign-keys mysql-error-1005

我与最常见的错误斗争但未能解决问题。

DROP TABLE IF EXISTS `tvguide_db`.`tvchanel` ;

CREATE  TABLE IF NOT EXISTS `tvguide_db`.`tvchanel` (
  `idtvchanel` VARCHAR(16) NOT NULL ,
  `chanelname` VARCHAR(64) NOT NULL ,
  `icon` VARCHAR(30) NOT NULL ,
  `category` VARCHAR(32) NOT NULL ,
  `genre` VARCHAR(45) NULL ,
  `description` VARCHAR(256) NULL ,
  `chanellanguage` VARCHAR(3) NOT NULL ,
  PRIMARY KEY (`idtvchanel`) ,
  UNIQUE INDEX `idtvchanel_UNIQUE` (`idtvchanel` ASC) )
ENGINE = InnoDB;

DROP TABLE IF EXISTS `subscriber_db`.`chanellist_planid` ;

CREATE  TABLE IF NOT EXISTS `subscriber_db`.`chanellist_planid` (
  `chanelid` VARCHAR(16) NOT NULL ,
  PRIMARY KEY (`chanelid`) ,
  UNIQUE INDEX `chanelid_UNIQUE` (`chanelid` ASC) ,
  CONSTRAINT `fk_chanellist_planid_chanelid`
    FOREIGN KEY (`chanelid` )
    REFERENCES `tvguide_db`.`tvchanel` (`idtvchanel` )
    ON DELETE RESTRICT
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

我收到此错误

ERROR 1005 (HY000): Can't create table 'subscriber_db.chanellist_planid' (errno: 150)

关于这个SHOW ENGINE INNODB状态;命令给了我这个。

131006  5:38:49 Error in foreign key constraint of table subscriber_db/chanellist_planid:

    FOREIGN KEY (`chanelid` )
    REFERENCES `tvguide_db`.`tvchanel` (`idtvchanel` )
    ON DELETE RESTRICT
    ON UPDATE NO ACTION)
ENGINE = InnoDB:
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
for correct foreign key definition.

任何解决方案。 在此先感谢。

0 个答案:

没有答案