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:
- mysql: [Err] 1075 – Incorrect table definition; there can be only one auto column and it must be d…
- [Solved] MySQL query reports an error: Legal mix of settlements
- MySQL ERROR 1005: Can’t create table (errno: 150) [How to Solve]
- [Solved] MySQL uses the workbench tool, and the table status is read only
- In Oracle, an error is reported: ora-00904
- MySQL Error Number 1005 Can’t create table (Errno:150)
- SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”
- MySQL timestamp set default value error Invalid default value reason and solution
- Failed to read auto-increment value from storage
- When mysql creates a table, set timestamp DEFAULT NULL error 1067-Invalid default value for’updated_at’