1

我试图放下一张桌子,在我遇到这个问题之前

并已成功解决,但现在我尝试删除表,但出现此错误:

ERROR: Error 1005: Can't create table 'radiotaxi_final.#sql-108_28' (errno: 150)

该声明 :

ALTER TABLE `RadioTaxi_Final`.`DireccionConductor` CHANGE COLUMN `Conductor_cedula` `Conductor_cedula` INT(11) NOT NULL  , 

  ADD CONSTRAINT `fk_DireccionConductor_Conductor1`

  FOREIGN KEY (`Conductor_cedula` )

  REFERENCES `RadioTaxi_Final`.`Conductor` (`cedula` )

  ON DELETE NO ACTION

  ON UPDATE NO ACTION

结果 :

SQL script execution finished: statements: 11 succeeded, 1 failed

桌子 :

CREATE TABLE `conductor` (  `cedula` int(10) unsigned NOT NULL,  `apellidos` varchar(30) COLLATE utf8_spanish2_ci NOT NULL,  `nombres` varchar(30) COLLATE utf8_spanish2_ci NOT NULL,  `fechaNacimiento` date NOT NULL,  PRIMARY KEY (`cedula`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish2_ci
4

1 回答 1

3

创建 时FOREIGN KEY,引用列和引用列的数据类型必须完全相同。在您引用的表conductor.cedula中,类型为INT(10) UNSIGNED. 您已尝试在DireccionConductor.Conductor_cedulaasINT(11)上隐式创建 FK SIGNED。如下修改您的语句以使类型匹配:

ALTER TABLE `RadioTaxi_Final`.`DireccionConductor`
  /* INT(10) UNSIGNED type matches the referenced table */
  CHANGE COLUMN `Conductor_cedula` `Conductor_cedula` INT(10) UNSIGNED NOT NULL  , 
  ADD CONSTRAINT `fk_DireccionConductor_Conductor1`
    FOREIGN KEY (`Conductor_cedula` )
    REFERENCES `RadioTaxi_Final`.`Conductor` (`cedula` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION
于 2013-03-04T15:08:57.283 回答