I have a little problem making some foreign keys...
When I try to define the foreign key in MySQL Workbench, I get the following message:
Selected column 'playerName' must be indexed and be of a compatible type for a Foreign Key to be created.
There my problem starts: I'm pretty sure, that the column (towns.playerName) is indexed and it's definitively of the same type ( VARCHAR(255) )...
Indexes of 'towns'
I want to add a Foreign Key from players.name (primary key, not null, unique)
to towns.playersName(not null)
.
So what can I do to get the foreign key created?
It seems i am doing something wrong...
PS: I'm sorry, if there is already a question for this...
EDIT: I just tried again (exactly as I did before several times) and now it works... really strange
Perhaps a bug in MySQL Workbench??
I got the same problem a number of times, but finally found a interesting and useful concept which I missed while learning mysql. If a column is not a 'key' in the table 1, you cannot add it as foreign key unless it should have an index. So I make the column a indexed column.
e.g.
CREATE INDEX any_name ON table1 (column1);
finally, I was able to solve my problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With