Warm tip: This article is reproduced from serverfault.com, please click

MySQL duplicate FK values in myPhpAdmin dropdown list

发布于 2020-11-27 14:28:00

I've built my first ever simple MySQL DB with the myPhpAdmin interface.

1st users table: id (PK), email, fname, lname, isConsultant [bool]...

2nd consultants table: id (PK), title, bio...

3rd table linking both (some users are consultants, some are not): id (PK), user_id (FK), consultant_id (FK).

I have Primary Key and Foreign Key well assigned (I've followed quite a few video tutorials).

Now when I test and try to insert values into my 3rd table, I see "duplicate" options offered to me by the myPhpAdmin interface:

screenshot of the dropdown list of FK values in myPhpAdmin

myPhpAdmin screenshot of the table structure with PK and index/FKs

What did I do wrong? Please if you could use simple wordings since I'm new to this!?

Questioner
Fred K
Viewed
0
Isaac Bennetch 2020-11-30 00:16:33

phpMyAdmin shows these foreign key relations sorted both ways — by the key and by the referenced name. That makes it easy for you to insert data regardless of whether you know the id is 1 or the corresponding value is Law.

You haven't done anything wrong, and it's a little confusing at first, but this is working exactly as intended. You can use either from the dropdown to pick the same value; it will insert the '1' regardless of whether you select "1 - Law" or "Law - 1".