Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #2257 -- MySQL wants constraint names to be unique per-database…

…, so fixed

the SQL generation to ensure this.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3373 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0016547e9b29db789c416fab74f39561db4e75ef 1 parent ab4ffe5
Malcolm Tredinnick authored July 19, 2006

Showing 1 changed file with 8 additions and 2 deletions. Show diff stats Hide diff stats

  1. 10  django/core/management.py
10  django/core/management.py
@@ -197,6 +197,7 @@ def _get_sql_for_pending_references(klass, pending_references):
197 197
     data_types = get_creation_module().DATA_TYPES
198 198
 
199 199
     final_output = []
  200
+    reference_names = {}
200 201
     if backend.supports_constraints:
201 202
         opts = klass._meta
202 203
         if klass in pending_references:
@@ -206,9 +207,14 @@ def _get_sql_for_pending_references(klass, pending_references):
206 207
                 r_col = f.column
207 208
                 table = opts.db_table
208 209
                 col = opts.get_field(f.rel.field_name).column
  210
+                r_name = '%s_referencing_%s_%s' % (r_col, table, col)
  211
+                if r_name in reference_names:
  212
+                    reference_names[r_name] += 1
  213
+                    r_name += '_%s' % reference_names[r_name]
  214
+                else:
  215
+                    reference_names[r_name] = 0
209 216
                 final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
210  
-                    (backend.quote_name(r_table),
211  
-                    backend.quote_name('%s_referencing_%s_%s' % (r_col, table, col)),
  217
+                    (backend.quote_name(r_table), r_name,
212 218
                     backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col)))
213 219
             del pending_references[klass]
214 220
     return final_output

0 notes on commit 0016547

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