Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #2257 -- make constraint names unique across all table/column

combinations (for the benefit of MySQL).


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3512 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fa5e0562dcdf438ca7c1285b6d69f6c31bf0c676 1 parent a7f8984
Malcolm Tredinnick authored August 01, 2006

Showing 1 changed file with 3 additions and 7 deletions. Show diff stats Hide diff stats

  1. 10  django/core/management.py
10  django/core/management.py
@@ -192,7 +192,6 @@ def _get_sql_for_pending_references(model, pending_references):
192 192
     data_types = get_creation_module().DATA_TYPES
193 193
 
194 194
     final_output = []
195  
-    reference_names = {}
196 195
     if backend.supports_constraints:
197 196
         opts = model._meta
198 197
         if model in pending_references:
@@ -202,12 +201,9 @@ def _get_sql_for_pending_references(model, pending_references):
202 201
                 r_col = f.column
203 202
                 table = opts.db_table
204 203
                 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))))
211 207
                 final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
212 208
                     (backend.quote_name(r_table), r_name,
213 209
                     backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col)))

0 notes on commit fa5e056

Please sign in to comment.
Something went wrong with that request. Please try again.