Projects » Constraint Name Generator

Constraint Name Generator

This is a plugin for MySQL Workbench that (re)generates foreign key, unique constraint, and index names according to the associated table and/or column names.

Please read the change log for details on how this plugin works. It's likely that you will have to adjust the unique constraint naming conventions to your own needs, as they can't be set anywhere in MySQL Workbench.

Latest version: 0.5
Release date: 2012-01-23
Download URL:


If already installed, just have the ZIP overwrite the file in your MySQL modules directory. If you have never installed this plugin before, drop the contents of the ZIP into any temporary  directory and use the MySQL Workbench Scripting -> Install Plugin/Module... menu item and browse to the unzipped file. Then a copy of the file will be created in the user's default plugin directory (on Windows 7 this is in %USERPROFILE%\AppData\Roaming\MySQL\Workbench\modules).

Change log:

# 0.5 (2012-01-23):
#    + [imp] Newer MySQL versions no longer support identical names for indexes and foreign keys.
#            See RFE here:
#            The code was adjusted to derive index names from foreign key names. Currently the
#            substrings "_fk_", "fk_", and "_fk" are replaced by "_idx_", "idx_", and "_idx", if
#            present (in that order).
#            Note:
#            WB actually requires a separate index pattern in the options due to the new naming
#            rules. This is because the plugin can't assume a fixed string to be present, e.g. "fk"
#            as above, nor can it reliably guess an index pattern from the foreign key pattern set
#            in the options.
#            See RFE here:
#    + [oth] Now includes a separate kawoolutions_util module, which basically is a collection of
#            utility methods that the internal WB classes don't provide. Note, the contents of this
#            module might change without notice.
# 0.4.2:
#    + [fix] Fixed unintentional prefixing, e.g. a multi-column FK (prequalification_id,
#            preference_id) would determine prefix "pre", but this might not be wanted. Optional
#            logic was added to kawoolutions_util.getPrefixFor to control a required underscore
#            as prefix delimiter as well as a minium prefix length (without underscore)
# 0.4.1:
#    + [fix] Fixed self references to not include same table name twice
# 0.4 (2011-08-17):
#    + [oth] Ported the plugin from Lua to Python
#    + [fix] Fixed the code to handle multiple foreign keys to the same table without creating
#            duplicate names. An attempt is made to guess from a common prefix of the columns to
#            include it in the generated name. In case of potential name collisions simple ordinal
#            numbers will be appended to the names.
#    + [imp] Renamed some methods
# 0.3:
#    + [imp] Adjusted the code to support renaming of foreign keys that don't have an index
# 0.2.1:
#    + [imp] Slightly adjusted the text of the BSD license
# 0.2:
#    + [imp] Now evaluating the model options check box to either read the
#            local or global Workbench foreign key naming conventions
# 0.1:
#    + [add] Generates unique constraint (index) names according to the HARDCODED naming
#            conventions:
#            - if multiple columns are used, the unique constraint (index) name will be
#              "%stable%_multi_uq"
#            - if a single column is used, the unique constraint (index) name will be
#              "%stable%_%column%_uq"
#    + [add] Generates foreign key (and index) names according to the GLOBAL Workbench
#            naming conventions:
#            - if source and destination tables are equal (self references), the foreign key (and
#              index) name will be "%stable%_self_fk"
#            - if source and destination tables are not equal, the foreign key (and index) name
#              will be "%stable%_%dtable%_fk"

Status: active