2014-02-23 139 views
0

我試圖轉發工程我的ERD工作臺6.0中的計劃,但我得到這個錯誤。我檢查過所有列類型,它們是一樣的。我在這裏查看了類似的問題,但仍然找不到答案。這裏的錯誤日誌:MYSQL錯誤:錯誤1215:無法添加外鍵約束

xecuting SQL script in server 

ERROR: Error 1215: Cannot add foreign key constraint 







-- ----------------------------------------------------- 

-- Table `proj`.`employee` 

-- ----------------------------------------------------- 

CREATE TABLE IF NOT EXISTS `proj`.`employee` (

    `employee_id` INT NOT NULL, 

    `position_id` INT NOT NULL, 

    PRIMARY KEY (`employee_id`), 

    CONSTRAINT `fk_employee_employee_history1` 

    FOREIGN KEY (`employee_id`) 

    REFERENCES `proj`.`employee_history` (`employee_id`) 

    ON DELETE NO ACTION 

    ON UPDATE NO ACTION, 

    CONSTRAINT `fk_employee_equipment_rentals1` 

    FOREIGN KEY (`employee_id`) 

    REFERENCES `proj`.`equipment_rentals` (`handling_employee_id`) 

    ON DELETE NO ACTION 

    ON UPDATE NO ACTION, 

    CONSTRAINT `fk_employee_scheduled_trips1` 

    FOREIGN KEY (`employee_id`) 

    REFERENCES `proj`.`scheduled_trips` (`leader`) 

    ON DELETE NO ACTION 

    ON UPDATE NO ACTION, 

    CONSTRAINT `fk_employee_scheduled_trips2` 

    FOREIGN KEY (`employee_id`) 

    REFERENCES `proj`.`scheduled_trips` (`assistant`) 

    ON DELETE NO ACTION 

    ON UPDATE NO ACTION) 

ENGINE = InnoDB 



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



Fetching back view definitions in final form. 

Nothing to fetch 
+0

不僅您的模式必須正確,任何現有的數據也必須通過約束。如果表中有任何新約束適用的數據必須滿足約束條件。我敢打賭你有一些孤兒數據。 – 2014-02-23 18:57:10

回答

0

所以事實證明,我的外鍵約束都搞砸了。我有關係倒退。我沒有使用外鍵引用主鍵,而是讓主鍵BE成爲引用非唯一列的外鍵。我扭轉了這一點,並且它工作。

相關問題