MySQL duplicate FK values in myPhpAdmin dropdown list

Viewed 67

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!?

2 Answers

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".

It looks like to me you inputted '1 - Law' as a string to consultant_id, and 'Law - 1' as a string to consultant_id as well, those two strings are not the same, so of course they will not be duplicated....

Related