网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 数据库 > MySQL教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Sybase教程,Access教程,DB2教程,数据库安全,数据库文摘
本月文章推荐
.解析:轻松了解 MySQL中损坏的My.
.使用MySql ODBC进行MYsql和MSsql.
.MySQL的AUTO_INCREMENT.
.MySQL修改密码方法总结.
.经验总结:修改MySQL默认密码的具.
.MYSQL EMS的乱码问题解决.
.MySQL中的mysqldump命令使用详解.
.无法远程登入MySQL的几种解决办法.
.讲解MySQL数据库字符集出错的解决.
.MySQL进阶_SELECT篇(三).
.在一台机器上,怎样开启两个mysq.
.MySQL进阶_SELECT篇(一).
.禁止Mysql默认端口访问Internet.
.NuSphere 让 MySQL 功能更强.
.轻松掌握MySQL数据库锁机制的相关.
.如何修护MYSQL数据表.
.巧用MySQL InnoDB引擎锁机制解决.
.MySQL入门学习(二).
.MySQL数据库中查找执行效率慢的S.
.MySQL优化全攻略-服务器参数调整.

解决由于操作不当出现的ERROR 1005错误

发表日期:2008-8-1


在使用MySQL的时候,在操作不当时,很容易出现 ERROR 1005 (HY000): Can't create table 这类错误。很多站长朋友可能需要排查很久才会找到问题的原因其实很简单,希望这篇文章可以对站长朋友以及Mysql初学者一点帮助。


MySQL官方提供的问题原因:


在信息中有一组【LATEST FOREIGN KEY ERROR】会有最近错误的详细描述和解决办法。


Cannot find an index in the referenced table where the referenced columns appear as the first columns, or column types in the table and the referenced table do not match for constraint.

(译:不能在“被reference的表”里找到包含“被reference字段”的索引,或者是两个关联字段类型不匹配)

 

以下介绍两个示例:


示例一:

 

程序代码


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 ,就不会报错了,创建表和修改表地时候常常一步小小就忘记了这个.

 

示例二:


MySQL里创建外键时(Alter table xxx add constraint fk_xxx foreign key),提示错误,但只提示很简单的信息:ERROR 1005 (HY000): Can't create table '.\env_mon\#sql-698_6.frm' (errno: 150)。根本起不到解决问题的作用。


drop table if exists products;

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;


create table 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,


constraint fk_items_product foreign key (product_id) references producets(id),


index(product_id)

primary key(id)

)type=innodb;

 

出现的报错:


ERROR 1005: Can't create table

 

主要问题以及解决办法是:


1,MySQL支持外键约束,并提供与其它DB相同的功能,但表类型必须为 InnoDB

2、建外键的表的那个列要加上index

上一篇:讲解更改MySQL数据库root密码的具体方法 人气:2023
下一篇:MySQL事件调度器Event Scheduler详解 人气:828
浏览全部MySQL的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐