2022-04-28
閱讀量:
1391
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));
執(zhí)行第一句, 然后執(zhí)行第二句后報錯如下
解決方法:
作為外鍵,dept表中的deptno必須是唯一值,因此得添加約束unique,或者primary key;
給第一句代碼加上unique,改為:
create table dept(deptno int unique ,dname varchar(15),loc varchar(10));
然后再執(zhí)行第二句就沒問題了
學(xué)習(xí)更多數(shù)據(jù)分析知識歡迎訪問 http://www.3lll3.cn/member.html?utm_source=weitao






評論(0)


暫無數(shù)據(jù)
推薦帖子
0條評論
1條評論
0條評論