Answer the question
In order to leave comments, you need to log in
How to organize a relationship in tables one to one mysql?
How to organize a one-to-one connection through the console. There are two tables Groups and Users.
There are 3 columns in the Groups table:
1. id
2. id_group
3. name
There are 3 columns in the Users table:
1. id
2. name_user
3. groups
there are 3 groups (1 - Easy, 2 - Medium, 3 - Hard)
if in the User table the groups column is given the number 2 to substitute from the Groups table name of the standing id_group.
I try like this
ALTER TABLE `groups` ADD FOREIGN KEY ( `name` ) REFERENCES `users` (`groups`) ON DELETE RESTRICT ON UPDATE RESTRICT ;
#1170 - BLOB column 'name' was specified in the key definition without specifying the key length
Answer the question
In order to leave comments, you need to log in
You are doing complete nonsense. Linking by text field is fundamentally not the right solution. In addition, I suspect that users.groups does not contain the name of one group, but a comma-separated list of groups! And this is generally game!
Why don't you have a group_id field and link users.group_id to groups.id?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question