加入收藏 | 设为首页 | 会员中心 | 我要投稿 云计算网_泰州站长网 (http://www.0523zz.com/)- 视觉智能、AI应用、CDN、行业物联网、智能数字人!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

ERROR 1005 (HY000): Can't create table错误的解决

发布时间:2016-01-17 19:21:45 所属栏目:MySql教程 来源:网络整理
导读:在使用MySQL的时候,在操作不当时,很容易出现 ERROR 1005 (HY000): Can't create table 这类错误。很多站长朋友可能需要排查很久才会找到问题的原因其实很简单
在使用MySQL的时候,在操作不当时,很容易出现 ERROR 1005 (HY000): Can't create table 这类错误。很多站长朋友可能需要排查很久才会找到问题的原因其实很简单,希望这篇文章可以对站长朋友以及Mysql初学者一点帮助。

MYSQL官方提供的问题原因:

在信息中有一组【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字段”的索引,或者是两个关联字段类型不匹配)

以下介绍两个示例:

示例一:

create table booktype
(
btid  int(5) unsigned zerofill auto_increment not null primary key,
btname varchar(100) not null unique,
btnote text
);
create table books
(
bid int(5) unsigned zerofill auto_increment not null primary key,
bname char(30) not null,
isbn char(50) not null,
author char(30) not null,
press  text,
summary text,
bcount int not null default 0,
btid  int,
foreign key(btid) references booktype(btid)
);

出现的报错:

ERROR 1005 (HY000): Can't create table '.bookdatabooks.frm' (errno: 150)

主要问题以及解决办法是:

foreign key(btid) references booktype(btid) 中books表的 btid  是int和booktype表中的btid设置的关联字段类型不匹配,books表中btid改正成:btid  int(5) unsigned zerofill ,就不会报错了,创建表和修改表地时候常常一步小小就忘记了这个.

(编辑:云计算网_泰州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读