2013-03-04 91 views
1

我嘗試刪除表之前,我有這個問題QUESTION錯誤1005無法創建表

,併成功地解決了,但現在我想刪除表,我得到這個錯誤:

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 
+1

150是外鍵創建錯誤。請張貼'RadioTaxi_Final.Conductor'表。 – 2013-03-04 14:55:13

回答

3

當創建一個FOREIGN KEY,引用和引用列的數據類型必須是正好相同。在您參考的表格中,conductor.cedula的類型爲INT(10) UNSIGNED。您試圖在DireccionConductor.Conductor_cedula上創建FK作爲INT(11),隱含地爲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 
+0

謝謝你的工作,但是像這樣:ALTER TABLE'RadioTaxi_Final'.'DireccionConductor' /* INT(10)UNSIGNED類型匹配參考表*/ CHANGE COLUMN'Conductor_cedula''Conductor_cedula' INT(10)UNSIGNED NOT NULL, ADD CONSTRAINT'fk_DireccionConductor_Conductor1' 外鍵('Conductor_cedula') 參考'RadioTaxi_Final'.'Conductor'('cedula') ON DELETE NO ACTION ON UPDATE NO ACTION – user2132046 2013-03-04 15:37:04

相關問題