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 展开
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 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询