MYSQL ERROR 1005 (HY000): Can’t create table [How to Solve]

A small problem I encountered today when creating a MYSQL database.

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:

ERROR 1005 (HY000): Can’t create table ‘.\bookdata\books.frm’ (errno: 150)

The main problem is that

foreign key(btid) references booktype(btid) in books table btid is int and booktype table btid set associated field type does not match, books table btid corrected to: btid int(5) unsigned zerofill, it will not report an error, creating tables and modifying tables often forget this in one small step.

Similar Posts: