Django

Code

Changeset 3512

Show
Ignore:
Timestamp:
08/01/06 16:46:51 (2 years ago)
Author:
mtredinnick
Message:

Fixed #2257 -- make constraint names unique across all table/column
combinations (for the benefit of MySQL).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management.py

    r3460 r3512  
    193193 
    194194    final_output = [] 
    195     reference_names = {} 
    196195    if backend.supports_constraints: 
    197196        opts = model._meta 
     
    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                # For MySQL, r_name must be unique in the first 64 characters. 
     205                # So we are careful with character usage here. 
     206                r_name = '%s_refs_%s_%x' % (r_col, col, abs(hash((r_table, table)))) 
    211207                final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \ 
    212208                    (backend.quote_name(r_table), r_name,