Ticket #9253: hexdigest.patch

File hexdigest.patch, 1.6 KB (added by krzych, 15 years ago)
  • django/db/backends/creation.py

     
    11import sys
    22import time
     3from django.utils.hashcompat import md5_constructor
    34try:
    45    set
    56except NameError:
     
    128129                col = opts.get_field(f.rel.field_name).column
    129130                # For MySQL, r_name must be unique in the first 64 characters.
    130131                # So we are careful with character usage here.
    131                 r_name = '%s_refs_%s_%x' % (r_col, col, abs(hash((r_table, table))))
     132                r_name = '%s_refs_%s_%s' % (r_col, col, md5_constructor(r_table + table).hexdigest()[:8])
    132133                final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \
    133134                    (qn(r_table), qn(truncate_name(r_name, self.connection.ops.max_name_length())),
    134135                    qn(r_col), qn(table), qn(col),
     
    187188            output.append('\n'.join(table_output))
    188189
    189190            for r_table, r_col, table, col in deferred:
    190                 r_name = '%s_refs_%s_%x' % (r_col, col,
    191                         abs(hash((r_table, table))))
     191                r_name = '%s_refs_%s_%s' % (r_col, col,
     192                        md5_constructor(r_table + table).hexdigest()[:8])
    192193                output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' %
    193194                (qn(r_table),
    194195                qn(truncate_name(r_name, self.connection.ops.max_name_length())),
Back to Top