2014-03-28 60 views
11

爲什麼我會收到此錯誤?我沒有任何外鍵Mysql無法創建表errno 121

drop table if exists t_issue; 
SET foreign_key_checks = 0;SET storage_engine=INNODB; 
CREATE TABLE `t_issue` (
`id_issue` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, 
`fk_project` int(11) DEFAULT NULL, 
`subject` varchar(255) DEFAULT NULL, 
`estimated_due_date` date DEFAULT NULL, 
`due_date` date DEFAULT NULL, 
`done_ratio` int(11) DEFAULT NULL, 
`fk_status` int(11) DEFAULT NULL, 
`fk_assigned_to` int(11) DEFAULT NULL, 
`fk_owner` int(11) DEFAULT NULL 
) ENGINE=innodb DEFAULT CHARSET=latin1 
+2

似乎爲我的工作確定。 – Malcolm

+0

[It's working](http://sqlfiddle.com/#!2/3d392)。你遇到什麼錯誤 –

+0

對我來說工作正常 – Sadikhasan

回答

28

MySQL不能創建表的錯誤號121

,如果你想添加一個約束與已在別處用過的名字,你會得到此消息。

要檢查約束,使用下面的SQL查詢:

SELECT 
    constraint_name, 
    table_name 
FROM 
    information_schema.table_constraints 
WHERE 
    constraint_type = 'FOREIGN KEY' 
AND table_schema = DATABASE() 
ORDER BY 
    constraint_name; 

參考:https://dba.stackexchange.com/questions/425/error-creating-foreign-key-from-mysql-workbench

參見:SQL - error code 1005 with error number 121

+0

我這樣做,沒有任何約束導致查詢正在我的當前查詢中使用生成此表 – patentul

+0

是的,我確實使用了一個約束,我替換了它,但它仍然不起作用 – patentul

+0

爲什麼,你得到了什麼...... – jmail

相關問題