Ticket #9253: hexdigest.patch
File hexdigest.patch, 1.6 KB (added by , 16 years ago) |
---|
-
django/db/backends/creation.py
1 1 import sys 2 2 import time 3 from django.utils.hashcompat import md5_constructor 3 4 try: 4 5 set 5 6 except NameError: … … 128 129 col = opts.get_field(f.rel.field_name).column 129 130 # For MySQL, r_name must be unique in the first 64 characters. 130 131 # 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]) 132 133 final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \ 133 134 (qn(r_table), qn(truncate_name(r_name, self.connection.ops.max_name_length())), 134 135 qn(r_col), qn(table), qn(col), … … 187 188 output.append('\n'.join(table_output)) 188 189 189 190 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]) 192 193 output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % 193 194 (qn(r_table), 194 195 qn(truncate_name(r_name, self.connection.ops.max_name_length())),