在MySQL里創(chuàng)建外鍵時(shí)(Alter table xxx add constraint fk_xxx foreign key),提示錯(cuò)誤,但只提示很簡(jiǎn)單的信息:ERROR 1005 (HY000): Can't create table '.\env_mon\#sql-698_6.frm' (errno: 150)。根本起不到解決問(wèn)題的作用。
要看錯(cuò)誤的詳細(xì)提示,可以使用命令:(在MySQL Manual里搜索“errno 150”時(shí)找到)
SHOW ENGINE INNODB STATUS;???? //針對(duì)用INNODB存儲(chǔ)方式的數(shù)據(jù)庫(kù)
在信息中有一組【LATEST FOREIGN KEY ERROR】會(huì)有最近錯(cuò)誤的詳細(xì)描述和解決辦法。
如:
Cannot find an index in the referenced table where the referenced columns appear as the first columns, or column types in the table and the referenced table do not match for constraint.
(譯:不能在“被reference的表”里找到包含“被reference字段”的索引,或者是兩個(gè)關(guān)聯(lián)字段類(lèi)型不匹配)
(我犯的錯(cuò)誤是沒(méi)有在主表中設(shè)置主鍵-_-!,即第一種原因)
版權(quán)所有 羅明