mysql 不能添加外键 1215cu

droptableifexistscompany;droptableifexistsfriends;droptableifexistsimage_text;droptab... drop table if exists company;

drop table if exists friends;

drop table if exists image_text;

drop table if exists news;

drop table if exists newstype;

drop table if exists user;

drop table if exists video;

create temporary table company
(
id int(8) not null,
name varchar(500),
path varchar(500),
primary key (id)
);

create temporary table friends
(
id int(8) not null,
content varchar(500),
image0 varchar(500),
image1 varchar(500),
image2 varchar(500),
user_id int(8),
primary key (id)
);

create temporary table image_text
(
id int(8) not null,
title varchar(500),
image varchar(500),
news_id int(8),
primary key (id)
);

create temporary table news
(
id int(8) not null,
title varchar(500),
tetail text,
image0 varchar(500),
image1 varchar(500),
image2 varchar(500),
time varchar(500),
type_id int(8),
company_id int(8),
primary key (id)
);

create temporary table newstype
(
id int(8) not null,
type varchar(100),
primary key (id)
);

create temporary table user
(
id int(8) not null,
name varchar(100),
qq varchar(200),
primary key (id)
);

create temporary table video
(
id int(8) not null,
path varchar(500),
primary key (id)
);

alter table friends add constraint FK_Reference_4 foreign key (user_id)
references user (id) on delete restrict on update restrict;

alter table image_text add constraint FK_Reference_2 foreign key (news_id)
references news (id) on delete restrict on update restrict;

alter table news add constraint FK_Reference_3 foreign key (company_id)
references company (id) on delete restrict on update restrict;

alter table news add constraint FK_Reference_5 foreign key (type_id)
references newstype (id) on delete restrict on update restrict;
这是报的错

[SQL]

alter table friends add constraint FK_Reference_4 foreign key (user_id)
references user (id) on delete restrict on update restrict;
[Err] 1215 - Cannot add foreign key constraint
展开
 我来答
爱生活free
2016-08-30 · TA获得超过421个赞
知道答主
回答量:85
采纳率:100%
帮助的人:22.2万
展开全部
可以先删除外键关联,执行结尾再加上
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式