MYSQL建表错误:ERROR 1050

关注:193  答案:2  mip版

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

已解决

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)有问题。但是排查不出来,求大神帮忙!!!

最佳答案

2021-01-16 21:41

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

全部回答

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

);

我要举报

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

点此我要举报以上信息!

推荐资讯

大家都在看

mysql外键1050_MYSQL建表错误:ERROR 1050相关推荐

  1. mysql建表 外键_mysql建表外键怎么设

    mysql建表外键怎么设 mysql建表时设置外键的方法:在"CREATE TABLE"语句中,通过"[CONSTRAINT ] FOREIGN KEY 字段名 [,字段 ...

  2. mysql建表外键_mysql建表外键怎么设?

    mysql建表时设置外键的方法:在"CREATE TABLE"语句中,通过"[CONSTRAINT ] FOREIGN KEY 字段名 [,字段名2,-] REFEREN ...

  3. MYSQL外键约束和表关联

    1. 外键约束 约束 : 约束是一种限制,它通过对表的行或列的数据做出限制,来确保表的数据的完整性.关联性 foreign key 功能 : 建立表与表之间的某种约束的关系,由于这种关系的存在,能够让 ...

  4. MYSQL外键(Foreign Key)的使用

    在MySQL 3.23.44版本后,InnoDB引擎类型的表支持了外键约束. 外键的使用条件: 1.两个表必须是InnoDB表,MyISAM表暂时不支持外键(据说以后的版本有可能支持,但至少目前不支持 ...

  5. MySQL——外键约束

    设置外键约束(FOREIGN KEY, FK ) MySQL外键约束是表的一个特殊字段,经常与外键约束一起使用.对于两个具有关联关系的表而言,相关字段中主键所在表称为主表(父表),外键所在表称为从表( ...

  6. mysql建表外键_mysql建表约束

    建表规约 [强制]:存储引擎必须使用 InnoDB 解读:InnoDB 支持事物.行级锁.并发性能更好,CPU 及内存缓存页优化使得资源利用率更高. [强制]:每张表必须设置一个主键 ID,且这个主键 ...

  7. mysql修改级联表数据_MySQL数据库 外键,级联, 修改表的操作

    1.外键: 用来建立两张表之间的关系 - 一对多 - 多对多 - 一对一 研究表与表之间的关系: 1.定义一张 员工部门表 id, name, gender, dep_name, dep_desc - ...

  8. oracle删除库里的所有表,清空mysql指定库里全部表数据-自动删除所有表,有外键约束的表优先删除...

    清空mysql指定库里所有表数据-自动删除所有表,有外键约束的表优先删除 由于要清空数据库数据 ,手动非常麻烦.网上找了一下,有一个Oracle的,参照它,在其上修改一下用于Mysql,把代码奉献如下 ...

  9. DBeaver mysql 外键设置了级联删除,子表无法添加数据

    DBeaver mysql 外键设置了级联删除,子表无法添加数据 报错:Cannot add or update a child row: a foreign key constraint fails ...

最新文章

  1. SpringInAction--自动化装配Bean(显示装配之xml配置)
  2. 对网站的代码采集实例
  3. android开发标签栏应该设置多少钱,android – Flutter:刷卡后默认标签栏控制器......
  4. 内存池和tcmalloc的性能比较
  5. c语言存储学生信息并显示,C语言实现学生信息管理程序
  6. 小结SQL Server连接失败错误及解决[引用]
  7. 华为云苏光牛:生态建设是数据库产业发展非常重要的一环
  8. matlab进行特征缩放,机器学习中(Feature Scaling)特征缩放处理的matlab实现方式
  9. 总结 10 年前端经验,谈谈前端人如何更快地成长
  10. extjs中grid中行内文本或图片居中显示
  11. element el-autocomplete组件 自定义传参的解决方法
  12. RS-485 接口 EMC 电路设计
  13. 虚拟空间 搬迁 云服务器,服务器空间搬迁到虚拟主机
  14. python 爱心名字代码_python写心形名字
  15. linux btrfs文件系统,btrfs 文件系统
  16. android网络测试上传速度慢,【教程】状态栏添加网速 《双排上传速度和下载速度》(转)...
  17. java神雕侠侣1古墓情缘游戏攻略_《神雕侠侣》手游古墓秘境1到5关详细攻略
  18. 机器学习一些核心概念的解读文档汇总
  19. Buffon's Needle
  20. 通讯录——C语言实现

热门文章

  1. 关于青春和奉献的名言范文
  2. vscode python插件_黄哥Python:VS Code 10个Python 插件
  3. 为什么现在老年人看上去普遍比较年轻
  4. 湖北武汉施工员考试铁路桥梁桩础施工策略研究建筑七大员考试
  5. U盘在自己电脑上打不开,别人电脑上却可以打开
  6. Arduino--矩阵键盘+指纹传感密码锁
  7. 张宇30讲要求掌握证明的定理汇总
  8. Android开发之在软件内录屏录画面,直接CV就能用
  9. Win7 USB接口无法使用/驱动错误/该设备无法启动。(代码10) 故障解决方法
  10. 算法基础课——第四章 数学知识(一)