原文出處:http://www.tkk7.com/Andyluo/archive/2006/10/06/73584.html
在MySQL里創(chuàng)建外鍵時(Alter table xxx add constraint fk_xxx foreign key),提示錯誤,但只提示很簡單的信息:ERROR 1005 (HY000): Can't create table '.\env_mon\#sql-698_6.frm' (errno: 150)。根本起不到解決問題的作用。
要看錯誤的詳細(xì)提示,可以使用命令:(在MySQL Manual里搜索“errno 150”時找到)
SHOW ENGINE INNODB STATUS; //針對用INNODB存儲方式的數(shù)據(jù)庫
在信息中有一組【LATEST FOREIGN KEY ERROR】會有最近錯誤的詳細(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字段”的索引,或者是兩個關(guān)聯(lián)字段類型不匹配)
(我犯的錯誤是沒有在主表中設(shè)置主鍵-_-!,即第一種原因)
呵呵,今天建數(shù)據(jù)庫等時出的錯誤是由第二種原因引起,即兩個關(guān)聯(lián)字段類型不匹配,萬能的互聯(lián)網(wǎng)啊。。。。。。
posted on 2007-03-22 10:38
阿蜜果 閱讀(12470)
評論(10) 編輯 收藏 所屬分類:
MySql