Skip to content
Advertisement

MySQL Foreign Key ERROR. Constraint key error

I can’t add a foreign key to an existing table. The error is as follows

Advertisement

Answer

I’ve written the schema below which is working. I advise against using the same name student_id for the constraint as already used for the column. I would prefer fk_student_id to avoid risk of an ambiguity or conflict at some point.

✓

✓

db<>fiddle here

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