Bug #45027 Default generated Foreign Key names are identical
Submitted: 22 May 2009 8:33 Modified: 10 Jun 2009 14:30
Reporter: Christian Hass Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Workbench Severity:S3 (Non-critical)
Version:5.1.12 OS:MacOS
Assigned to: Alfredo Kojima CPU Architecture:Any
Tags: CHECKED, FK names Default generated Foreign Key names unique

[22 May 2009 8:33] Christian Hass
Description:
Foreign Key names must be unique. But default generated FK names are identical under certain circumstances.

FK names are usually generated from the name of the relation-table and the name of the other table. 
 - fk_<relation-table-name>_<table1>
 - fk_<relation-table-name>_<table2>

If you create two n-m relations between the same tables - and rename the first relation-table before creating the second - FK names of both relations are identical. This is due to the fact that the second relation-table again has the name: <table1>_has_<table2>
Which in return leads to the same FK names.
first n-m relation:
 - fk_<relation-table-name>_<table1>
 - fk_<relation-table-name>_<table2>
second n-m relation:
 - fk_<relation-table-name>_<table1>
 - fk_<relation-table-name>_<table2>

If you don't rename the first relation-table, a number is added to the name of the relation-table and you don't have any problems as the following FK names are used:
first n-m relation:
 - fk_<relation-table-name>_<table1>
 - fk_<relation-table-name>_<table2>
second n-m relation:
 - fk_<relation-table-name>1_<table1>
 - fk_<relation-table-name>1_<table2>

How to repeat:
1. Create 2 tables: e.g. Users and Books
2. Create a n-m Relation between these 2 tables. The click-order is important! 
    (First click on Users, then on Books)
3. Rename this Relation. eg. Borrowed
4. Create another n-m Relation. User the same click-order as above: First click on Users, then on Books.
5. Try to run SQL Create Script

Suggested fix:
Check if generated FK name already exists.
[22 May 2009 17:26] Valeriy Kravchuk
Thank you for the bug report. Verified just as described, but with 1:n relationship instead of m:n.
[4 Jun 2009 8:53] Johannes Taxacher
this is fixed. fix will be included in 5.1.13
[10 Jun 2009 14:30] Tony Bedford
An entry was added to the 5.1.13 changelog:

Foreign key names must be unique. However, MySQL Workbench default generated foreign key names were sometimes identical, causing Forward Engineer SQL CREATE Script to fail.