Skip to content
Advertisement

Error Code: 1826. Duplicate foreign key constraint name ‘menu_ibfk_1’

I am writing a code on MySQL and it’s giving me errors.

This is my code and it’s giving me the error – “Error Code: 1826. Duplicate foreign key constraint name ‘menu_ibfk_1’ “

When I give a different constraint name, it give me the error – “Error Code: 1822. Failed to add the foreign key constraint. Missing index for constraint ‘menu_ibfk_2’ in the referenced table ‘menu'”

This is the snapshot of MySQL output

MySQL output snapshot

What am I doing wrong?

Advertisement

Answer

A foreign key must reference the complete key:

And each constraint must have its own, unique name.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement