在MySQL里创建外键时(Alter table xxx add constraint fk_xxx foreign key),提示错误,但只提示很简单的信息:ERROR 1005 (HY000): Can't create table '.\env_mon\#sql-698_6.frm' (errno: 150)。根本起不到解决问题的作用。

要看错误的详细提示,可以使用命令:(在MySQL Manual里搜索“errno 150”时找到)

SHOW ENGINE INNODB STATUS;     //针对用INNODB存储方式的数据库

在信息中有一组【LATEST FOREIGN KEY ERROR】会有最近错误的详细描述和解决办法。
如:
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字段”的索引,或者是两个关联字段类型不匹配)

(我犯的错误是没有在主表中设置主键-_-!,即第一种原因)

版权所有 罗明
posted on 2006-10-06 22:53 罗明 阅读(4709) 评论(18)  编辑  收藏 所属分类: Database
Comments

只有注册用户登录后才能发表评论。


网站导航: