mysql外键1050_MYSQL建表错误:ERROR 1050

MYSQL建表错误:ERROR 1050

关注:193  答案:2  mip版

解决时间 2021-01-17 09:33

e6cb1a03ad541b3098697807b7bf1798.png

已解决

2021-01-16 20:50

五张表:

create table user(

id int auto_increment,

username varchar(50) not null,

password char(32) not null,

emailvarchar(50) not null,

address varchar(50) not null,

primary key (id),

unique (username,email)

)

create table product(

id int auto_increment,

productName varchar(100) not null,

price float not null,

producer varchar(100) default '',

primary key (id)

)

create table buy(

id int auto_increment,

userID int not null,

productID int not null,

num int not null default 1,

primary key (id),

foreign key (userID) references user(id),

foreign key (productID) references product(id)

)

create table productOrder(

id int,

productID int not null,

num int not null default 1,

primary key (id),

foreign key (productID) references product(id)

)

create table orderDetail(

orderID int not null,

userID int not null,

sendUser varchar(50) not null,

sendAddress varchar(50) not null,

buyTime int not null,

userEmail varchar(50) not null,

foreign key (orderID) references productOrder(id),

foreign key (userID) references user(id),

foreign key (sendUser) references user(username),

foreign key (sendAddress) references user(address),

foreign key (userEmail) references user(email)

)

创建oderDetail时出现error:1050的错误。经过排除是因为外键foreign key (userEmail) references user(email)和foreign key (sendAddress) references user(address)有问题。但是排查不出来,求大神帮忙!!!

最佳答案

e6cb1a03ad541b3098697807b7bf1798.png

2021-01-16 21:41

外键这东西应该是其他表的主键吧?你user表有这么多主键??

全部回答

e6cb1a03ad541b3098697807b7bf1798.png

1楼

2021-01-16 22:07

enum括号里的内容,加上引号试试 enum('0','1') enum('n','a')

错误提示了有所说明了。“……near '0,1),……”,在 0,1)附近有错。

create table userinfo(

id int primary key not null auto_increment,

name varchar(15) not null,

job tinyint not null,

level tinyint not null default 1,

cap tinyint not null,

cloth tinyint not null,

weapon_display tinyint not null,

weapon_2 tinyint,

weapon_3 tinyint,

weapon_near enum('0','1'),

shoe tinyint not null,

money int not null,

passwordbag int not null,

team int not null,

company int,

hp int not null,

mp int not null,

exp int not null,

liliang int not null,

tizhi int not null,

minjie int not null,

wuxing int not null,

fuyuan int not null,

wugong int not null,

wufang int not null,

speed int not null,

canpluspoint tinyint not null,

qianneng int not null,

lastmap tinyint,

lastx int,

lasty int,

shifu int,

tudi_1 int,

tudi_2 int,

tudi_3 int,

tudi_4 int,

tudi_5 int,

islogin enum('0','1') not null,

lastlogintime datetime,

role enum('n','a'),

hpshangxian int not null,

mpshangxian int not null,

expsuoxu int not null,

dollar int not null

);

我要举报

如果感觉以上信息为低俗/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!

点此我要举报以上信息!

推荐资讯

大家都在看

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值