我试图放弃一张桌子,然后才遇到这个问题QUESTION
并且成功地解决了但是现在我试图放弃桌子并且我得到了这个错误:
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
答案 0 :(得分:3)
创建FOREIGN KEY
时,引用列和引用列的数据类型必须完全相同。在您引用的表格中,conductor.cedula
的类型为INT(10) UNSIGNED
。您试图在DireccionConductor.Conductor_cedula
上INT(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