mysql 创建外键:ERROR 1005: Can't create table

2007年6月28日MySql错误:ERROR 1005: Can't create table 2007-06-28 21:35:49

一,sql脚本(红色为修改后正确的语句)

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 四 更改表的type语句        alter table type=innoDB 五.创建索引       create index indexName on article_class(article_class_id); 六 .创建外建      alter table jspmo add constraint FK_Reference_1 foreign key (class_id)       references article_class (article_class_id) on delete restrict on update restrict;

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值