且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL错误1822:无法添加外键约束;存在约束BUT索引的缺失索引

更新时间:2022-11-08 18:27:33

问题在这里:

add foreign key(txtAC_tag) references tblaircrafts(txtAC_tag);

在这里,您以外键关系将txtAC_tag绑定到tblaircrafts表的txtAC_tag,但是在tblaircrafts中,列txtAC_tag既不是unique也不是primary,这就是它显示错误的原因.

here you are binding txtAC_tag to txtAC_tag of tblaircrafts table in a foreign key relationship but in tblaircrafts the column txtAC_tag is neither unique nor primary that's why it is showing error.

对于外键关系,要在其上创建关系的父表列必须为uniqueprimary,并且它们也必须具有相同的数据类型.

For foreign key relationship the parent table column on which you are creating relation must be unique or primary and they must have the same datatype also.

要解决此问题,请使txtAC_tag列唯一.

To resolve this make txtAC_tag column unique.