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的数据表。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM