mysql8.0添加外键报错 1824 - Failed to open the referenced table 'tb_dept1'

CREATE TABLE tb_emp5
(
id INT(11) PRIMARY KEY,
name VARCHAR(25),
deptId INT(11),
salary FLOAT,
CONSTRAINT fk_emp_dept1 FOREIGN KEY(deptId) REFERENCES tb_dept1(id)
);

 

报错

1824 - Failed to open the referenced table 'tb_dept1'

 

创建外键报错分析,constraint 为关键字,fk_emp_dept1为外键名称  ,foreign key(deptId) 为定义外键的关键字(此为从表)

tb_dept1(id)(此为主表),以上报错是数据库中没有创建tb_dept1的数据表。

posted @ 2021-06-07 20:17  中国一片天  阅读(7459)  评论(0编辑  收藏  举报