0
我嘗試添加外鍵:無法添加外鍵的MySQL:錯誤號150
CREATE TABLE `invoices` (
`id` int(11) NOT NULL AUTO_INCREMENT,
` name` varchar(255) NOT NULL,
`code_text` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `leads` (
`lead_id` int(11) NOT NULL AUTO_INCREMENT,
...
PRIMARY KEY (`lead_id`)
);
CREATE TABLE `leads_invoices` (
leads_invoice_id int(11) AUTO_INCREMENT NOT NULL,
invoice_id int(11) NOT NULL,
lead_id_i int(11) NOT NULL,
PRIMARY KEY(leads_invoice_id),
FOREIGN KEY (invoice_id) REFERENCES invoices(id),
FOREIGN KEY (lead_id_i) REFERENCES leads(lead_id)
ON UPDATE CASCADE
ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8
但我得到的錯誤與我lead_id_i鍵:
無法創建表
crm_test
。leads_invoices
(錯誤:150「外國 鍵約束的格式不正確」)
我檢查了所有類型和表,看來他們是正確的.. 我怎樣才能解決這個問題?希望你能幫助我。謝謝!
謝謝,它救了我 –
@ babboe2babboe2歡迎您 – Jens