`
alex09
  • 浏览: 969334 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

MYSQL can't create table(errno:150)

阅读更多
今天创建一个MYSQL数据库时遇到的一个小问题:
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 '.\bookdata\books.frm' (errno: 150)

主要问题是:

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

相关推荐

Global site tag (gtag.js) - Google Analytics