sql出错

来源:2-3 实体类设计与表创建B

慕仰3091474

2019-05-01

[SQL]CREATE TABLE tb_wechat_auth(
wechat_auth_id INT(10) not NULL AUTO_INCREMENT ,
user_id int(10) not NULL,
open_id VARCHAR(1024) NOT NULL,
create_time datetime DEFAULT null,
PRIMARY KEY(wechat_auth_id),
CONSTRAINT fk_wechatauth_profile FOREIGN KEY(user_id) FOREIGN KEY(user_id) REFERENCES tb_person_info(user_id)
)ENGINE=InnoDB auto_increment =1 default charset=utf8;
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘FOREIGN KEY(user_id) REFERENCES tb_person_info(user_id)
)ENGINE=InnoDB auto_inc’ at line 7

写回答

1回答

翔仔

2019-05-02

这个错误比较明显,说是CONSTRAINT附近 ,已经提示错误了 为什么会有两个FOREIGN KEY(user_id) FOREIGN KEY(user_id)?

CREATE TABLE `tb_wechat_auth` (
  `wechat_auth_id` int(10) NOT NULL AUTO_INCREMENT,
  `user_id` int(10) NOT NULL,
  `open_id` varchar(80) NOT NULL DEFAULT '',
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`wechat_auth_id`),
  UNIQUE KEY `open_id` (`open_id`),
  KEY `fk_wechatauth_profile` (`user_id`),
  CONSTRAINT `fk_wechatauth_profile` FOREIGN KEY (`user_id`) REFERENCES `tb_person_info` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;


0
0

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5137 学习 · 8152 问题

查看课程