Chinaz.com - 中国站长站

匿名投稿 投稿指南 RSS订阅 站长资讯通告:
搜索: 您的位置主页>网络编程>Mysql>阅读资讯:MYSQL使用错误 MYSQL中ERROR 1005

MYSQL使用错误 MYSQL中ERROR 1005

2008-05-29 09:03:45 来源:互联网 作者:编辑整理 【 评论:1

示例二:

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

Tags:MYSQL错误   1005   MySQL   Can   t   CREATE   table  
责任编辑:远行客
  • 请文明参与讨论,禁止漫骂攻击。 用户名:新注册) 密码: 匿名:
    评论总数: [ 查看全部 ] 网友评论
    关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助