Question

I'm try to create a foreign key between tables by using MySQL Workbench. But I don't know why I can't tick the checkbox to select a field in order to map with another field in another table. Maybe it require both field has the same type (and other conditions??) So can you tell me the criteria to create relationship using foreign key and how to do it in MySQL Workbench?

Was it helpful?

Solution

I'm not a user of MySQL Workbench, but make sure you're using a storage engine that supports foreign keys in the first place. (for example, InnoDB)

See the MySQL documentation for the requirements necessary for a foreign key relationship.

OTHER TIPS

I had this problem too. The reason I couldn't create the relationship was as you say the types weren't exactly the same. I had an unsigned int as my primary key and a signed int as my foreign key, so the software wouldn't allow me to create the relationship. Would have been nice if the software came up with an alert or some kind of user feedback highlighting it's objection to checking that box.

I had the same issue. Found a workaround:

After you have entered name of foreignkey constraint and selected the referenced table click "next" without selecting the column names.

In this step you will see the create sql script of new constraint. Edit it manually: enter the referenced column name and the column name of fk. Then click finish. The script will be executed. For recheck try to open table alter window again and you will see that the column checkbox is ticked now in foreign key tab.

When you edit a table in the EER diagram editor, there's a "Foreign Keys" tab. You can set the foreign keys between tables there. (Workbench 5.2.36)

I am facing the same problem with MySql Workbench. I have one char(5) (in table 1) as my primary key and another char(5) (in table 2) as a foreign key. But MySql Workbench won't let me create the relationship. I am using INNODB.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top