当前位置: 电脑软硬件应用网 > 设计学院 > 网络编程 > 数据库 > 正文 |
|
|||
解决由于操作不当出现的ERROR 1005错误 | |||
2008-8-4 0:47:58 文/Anna 出处:赛迪网 | |||
在使用MySQL的时候,在操作不当时,很容易出现 ERROR 1005 (HY000): Can't create table 这类错误。很多站长朋友可能需要排查很久才会找到问题的原因其实很简单,希望这篇文章可以对站长朋友以及Mysql初学者一点帮助。
(译:不能在“被reference的表”里找到包含“被reference字段”的索引,或者是两个关联字段类型不匹配)
以下介绍两个示例:
程序代码
( btid int(5) unsigned zerofill auto_increment not null primary key, btname varchar(100) not null unique, btnote text );
( 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) );
出现的报错:
程序代码
主要问题以及解决办法是:
示例二:
create table products( id int not null auto_increment, title varchar(100) not null, description text not null, image_url varchar(200) not null, price decimal(10,2) not null, date_available datetime not null, primary key(id) )type=innodb;
drop table if exists line_items;
id int not null auto_increment, product_id int not null, quantity int not null default 0, unit_price decimal(10,2) not null,
primary key(id) )type=innodb;
出现的报错:
主要问题以及解决办法是:
2、建外键的表的那个列要加上index |
|||
关于45IT | About 45IT | 联系方式 | 版权声明 | 网站导航 | |
Copyright © 2003-2011 45IT. All Rights Reserved 浙ICP备09049068号 |