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的数据表。
mysql8.0添加外键报错 1824 - Failed to open the referenced table 'tb_dept1'
原文:https://www.cnblogs.com/CHINA-YPT/p/14860387.html