mysql 添加外键报错,Error Code: 1215. Cannot add foreign key constraint 50
我的四个表如下:createtableTUser(uidintauto_incrementprimarykey,employNovarchar(20)notnulluni...
我的四个表如下:
create table TUser(
uid int auto_increment primary key,
employNo varchar(20) not null unique,
employName varchar(20) not null,
password varchar(20) not null,
administratorflag varchar(5) not null,
mobile varchar(20),
email varchar(64),
gen_time datetime not null,
login_time datetime,
last_login_time datetime,
count int not null
)
create table TDepartment(
did int primary key auto_increment,
deptNo varchar(20) not null unique,
deptName varchar(64) not null,
pdid int ,
cid int not null,
memo varchar(200),
foreign key(cid) references TCompany(cid) on delete cascade on update cascade
)
-- 职位表(TPosition)
create table TPostition(
pid int primary key auto_increment,
positionCode varchar(20) not null unique,
positionName varchar(64) not null
)
但是在创建下面这个表的时候报错。
create table TDepartmentUserRelation(
duid int not null auto_increment,
uid int not null,
did int not null,
pid int not null,
memo varchar(200),
primary key(duid),
foreign key(uid) references TUser(uid) on delete cascade on update cascade,
foreign key(did) references TDepartment(did) on delete cascade on update cascade,
foreign key(pid) references TPosition(pid) on delete cascade on update cascade
)
报的是
Error Code: 1215. Cannot add foreign key constraint
。。先谢谢了! 展开
create table TUser(
uid int auto_increment primary key,
employNo varchar(20) not null unique,
employName varchar(20) not null,
password varchar(20) not null,
administratorflag varchar(5) not null,
mobile varchar(20),
email varchar(64),
gen_time datetime not null,
login_time datetime,
last_login_time datetime,
count int not null
)
create table TDepartment(
did int primary key auto_increment,
deptNo varchar(20) not null unique,
deptName varchar(64) not null,
pdid int ,
cid int not null,
memo varchar(200),
foreign key(cid) references TCompany(cid) on delete cascade on update cascade
)
-- 职位表(TPosition)
create table TPostition(
pid int primary key auto_increment,
positionCode varchar(20) not null unique,
positionName varchar(64) not null
)
但是在创建下面这个表的时候报错。
create table TDepartmentUserRelation(
duid int not null auto_increment,
uid int not null,
did int not null,
pid int not null,
memo varchar(200),
primary key(duid),
foreign key(uid) references TUser(uid) on delete cascade on update cascade,
foreign key(did) references TDepartment(did) on delete cascade on update cascade,
foreign key(pid) references TPosition(pid) on delete cascade on update cascade
)
报的是
Error Code: 1215. Cannot add foreign key constraint
。。先谢谢了! 展开
佳达源
2024-10-28 广告
2024-10-28 广告
AR0144CSSM20SUKA0-CPBR这款产品,作为我司产品线中的重要一员,集成了高精度的传感器技术与先进的图像处理算法,广泛应用于安防监控、工业自动化及机器视觉等领域。其卓越的性能与稳定性,确保了在各种复杂环境下的精准数据采集与高效...
点击进入详情页
本回答由佳达源提供
展开全部
create table TPostition(
pid int primary key auto_increment,
positionCode varchar(20) not null unique,
positionName varchar(64) not null
)
与
foreign key(pid) references TPosition(pid) on delete cascade on update cascade
)
中的TPostition拼错了!!
pid int primary key auto_increment,
positionCode varchar(20) not null unique,
positionName varchar(64) not null
)
与
foreign key(pid) references TPosition(pid) on delete cascade on update cascade
)
中的TPostition拼错了!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询