Bug #80006 Incorrect/autonumbered foreign key, index and relationship name
Submitted: 15 Jan 2016 13:56 Modified: 24 May 2018 15:29
Reporter: M S Email Updates:
Status: QA review Impact on me:
None 
Category:MySQL Workbench: Modeling Severity:S3 (Non-critical)
Version:6.3.6 Build 511 CE 64-bit OS:Windows (7 Professional)
Assigned to: CPU Architecture:Any
Tags: fk name, foreign key name, relationship name

[15 Jan 2016 13:56] M S
Description:
There is an option within Preferences, to set auto-naming of foreign keys:
Workbench Preferences > Foreign Key/Relationship Defaults > FK Name:
which is by default set as: "fk_%stable%_%dtable%"

1.
Using this default value, creating a relationship the name gets number "1" attached to default value -- so in case of two tables "User" and "Country", the FK becomes: "fk_user_country1", instead of expected: "fk_user_country" (without number 1 at the end of the relation name).

2.
Besides, this affects the newly automatically created index name, which becomes: "fk_user_country1_idx", instead of just: "fk_user_country_idx".

Currently there is no way of easy removing this number at the end of a name, so we must manually rename all relationships and indexes.

How to repeat:
Just create two tables with arbitrary columns and create a relationship. The newly created relationship will have number 1 attached to the "fk_..." name.

Suggested fix:
1.
Disable auto numbering of FK names, to reflect value set in Preferences (fk_%stable%_%dtable%).

or:

2.
Add an option to enable/disable of FK/relationship numbering.
[15 Jan 2016 19:19] MySQL Verification Team
FK name

Attachment: fk_name.png (image/png, text), 120.58 KiB.

[15 Jan 2016 19:20] MySQL Verification Team
I couldn't repeat please provide a model test case before to create the FK. Thanks.
[17 Jan 2016 16:42] M S
FK Test Case

Attachment: fk-test-case.mwb (application/octet-stream, text), 8.76 KiB.

[17 Jan 2016 16:48] M S
Thank you for your reply. I've just added a "test case" file to this report, so please take a look at it. Eventually I've found another insteresting thing: The issue appears only if the tables have AI (Auto-increment) fields, as you can see there are two relations in this model:

a)
USER and COUNTRY table, without using AI feature on ID columns -- the FK is named correctly: "fk_user_country".

b)
A and B table, using AI feature on ID columns -- the FK is named incorrectly (there is number 1 attached to name): "fk_b_a1".

Hopefully is this not feature?
[17 Jan 2016 17:27] MySQL Verification Team
Thank you for the feedback