tb_wechat_auth和tb_local_auth无法创建外键约束
来源:2-3 实体类设计与表创建B
黑黑鸟
2018-11-04
use o2o;
CREATE TABLE tb_person_info
(user_id
int(10) NOT NULL AUTO_INCREMENT,name
varchar(32) DEFAULT NULL,profile_img
varchar(1024) DEFAULT NULL,email
varchar(1024) DEFAULT NULL,gender
varchar(2) DEFAULT NULL,enable_status
int(2) NOT NULL DEFAULT ‘0’ COMMENT ‘0:禁止访问,1:允许访问’,user_type
int(2) NOT NULL DEFAULT ‘1’ COMMENT ‘1:顾客,2:店家,3:超级管理员’,create_time
datetime DEFAULT NULL,last_edit_time
datetime DEFAULT NULL,
PRIMARY KEY (user_id
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
USE o2o;
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
) REFERENCEStb_person_info
(user_id
)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLEtb_local_auth
(local_auth_id
INT(10) NOT NULL AUTO_INCREMENT,user_id
INT(10) NOT NULL,username
VARCHAR(128) NOT NULL,password
VARCHAR(128) NOT NULL,createtime
DATETIME DEFAULT NULL,last_edit_time
DATETIME DEFAULT NULL,
PRIMARY KEY(local_auth_id
),
UNIQUE KEY uk_local_profile
(username
),
CONSTRAINT fk_localauth_profile
FOREIGN KEY(user_id
) REFERENCEStb_person_info
(user_id
)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
查询:CREATE TABLE tb_wechat_auth
( wechat_auth_id
INT(10) NOT NULL AUTO_INCREMENT, user_id
int(10) NOT NULL, open_id
VARCHAR(1…错误代码: 1215
Cannot add foreign key constraint
执行耗时 : 0 sec
传送时间 : 0 sec
总耗时 : 0.086 sec
查询:CREATE TABLEtb_local_auth
( local_auth_id
INT(10) NOT NULL AUTO_INCREMENT, user_id
INT(10) NOT NULL, username
VARCHAR(128…错误代码: 1215
Cannot add foreign key constraint
执行耗时 : 0 sec
传送时间 : 0 sec
总耗时 : 0.088 sec
请问如何解决
2回答
-
黑黑鸟
提问者
2018-11-10
CONSTRAINT fk_localauth_profile FOREIGN KEY(user_id) REFERENCEStb_person_info(user_id)
REFERENCES 和 tb_person_info(user_id)少了个空格
00 -
翔仔
2018-11-05
同学好,1215的错误可以参考如下链接逐项排查https://cloud.tencent.com/developer/article/1005293 这些表需要一个个去创建哈,而且我看同学的CREATE TABLEtb_local_auth( TABLE和tb_local_auth连在一起了,请分开,非常抱歉昨天团建去了,回复得不及时
012018-11-10
相似问题