Ticket #2257: 2257_fullname_1.patch

File 2257_fullname_1.patch, 1.2 KB (added by bill@…, 9 years ago)

supplies db wide unique fk names (for mysql)

  • management.py

     
    192192    data_types = get_creation_module().DATA_TYPES
    193193
    194194    final_output = []
    195     reference_names = {}
    196195    if backend.supports_constraints:
    197196        opts = model._meta
    198197        if model in pending_references:
     
    202201                r_col = f.column
    203202                table = opts.db_table
    204203                col = opts.get_field(f.rel.field_name).column
    205                 r_name = '%s_referencing_%s_%s' % (r_col, table, col)
    206                 if r_name in reference_names:
    207                     reference_names[r_name] += 1
    208                     r_name += '_%s' % reference_names[r_name]
    209                 else:
    210                     reference_names[r_name] = 0
     204                r_name = '%s_%s_references_%s_%s' % (r_table, r_col, table, col)
    211205                final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
    212206                    (backend.quote_name(r_table), r_name,
    213207                    backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col)))
Back to Top