2022-04-28
阅读量:
1340
mysql报错1822 :Failed to add the foreign key constraint. Missing index for constraint empo_ibfk_1
第一句代码: create table dept(deptno int,dname varchar(15),loc varchar(10));
第二句代码:
create table empo(empno int, ename varchar(15) unicode, job varchar(10) not null, mgr int, hiredate date, sal float default 4000, comn decimal,
deptno int, foreign key (deptno) references dept (deptno));
执行第一句, 然后执行第二句后报错如下
解决方法:
作为外键,dept表中的deptno必须是唯一值,因此得添加约束unique,或者primary key;
给第一句代码加上unique,改为:
create table dept(deptno int unique ,dname varchar(15),loc varchar(10));
然后再执行第二句就没问题了
学习更多数据分析知识欢迎访问 https://www.cda.cn/member.html?utm_source=weitao






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论