diff -r 1a34cdd59170 django/db/backends/creation.py
a
|
b
|
|
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: |
… |
… |
|
126 | 127 | r_col = f.column |
127 | 128 | table = opts.db_table |
128 | 129 | col = opts.get_field(f.rel.field_name).column |
129 | | # For MySQL, r_name must be unique in the first 64 characters. |
| 130 | # For MySQL, r_name must be unique in the first 64 characters |
| 131 | # and Oracle identifier lengths have a limit of 30 characters. |
130 | 132 | # So we are careful with character usage here. |
131 | | r_name = '%s_refs_%s_%x' % (r_col, col, abs(hash((r_table, table)))) |
| 133 | r_name = '%s_refs_%s_%s' % (r_col, col, |
| 134 | md5_constructor(r_table + table).hexdigest()[:8]) |
132 | 135 | final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \ |
133 | 136 | (qn(r_table), qn(truncate_name(r_name, self.connection.ops.max_name_length())), |
134 | 137 | qn(r_col), qn(table), qn(col), |
… |
… |
|
187 | 190 | output.append('\n'.join(table_output)) |
188 | 191 | |
189 | 192 | 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)))) |
| 193 | r_name = '%s_refs_%s_%s' % (r_col, col, |
| 194 | md5_constructor(r_table + table).hexdigest()[:8]) |
192 | 195 | output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % |
193 | 196 | (qn(r_table), |
194 | 197 | qn(truncate_name(r_name, self.connection.ops.max_name_length())), |
… |
… |
|
289 | 292 | col = f.column |
290 | 293 | r_table = model._meta.db_table |
291 | 294 | r_col = model._meta.get_field(f.rel.field_name).column |
292 | | r_name = '%s_refs_%s_%x' % (col, r_col, abs(hash((table, r_table)))) |
| 295 | r_name = '%s_refs_%s_%x' % (col, r_col, |
| 296 | md5_constructor(table + r_table).hexdigest()[:8]) |
293 | 297 | output.append('%s %s %s %s;' % \ |
294 | 298 | (style.SQL_KEYWORD('ALTER TABLE'), |
295 | 299 | style.SQL_TABLE(qn(table)), |