今天建立一個MYSQL數據庫時遇到的一個小問題:web
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)
);spa
出現的報錯:orm
ERROR 1005 (HY000): Can't create table '.\bookdata\books.frm' (errno: 150)ci
主要問題是:rem
foreign key(btid) references booktype(btid) 中books表的 btid 是int和booktype表中的btid設置的關聯字段類型不匹配,books表中btid改正成:btid int(5) unsigned zerofill ,就不會報錯了,建立表和修改表地時候經常一步小小就忘記了這個.it