3

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?

5 Answers 5

7

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

1 Comment

Oh yeah, I can see the problem. I set the difference collation for two field. I revised, using one consistent collation and now I can make the relation. Thank you
1

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.

Comments

0

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)

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.