Author: mtredinnick
Date: 2006-07-19 05:14:43 -0500 (Wed, 19 Jul 2006)
New Revision: 3373

Modified:
   django/trunk/django/core/management.py
Log:
Fixed #2257 -- MySQL wants constraint names to be unique per-database, so fixed
the SQL generation to ensure this.


Modified: django/trunk/django/core/management.py
===================================================================
--- django/trunk/django/core/management.py      2006-07-19 05:50:33 UTC (rev 
3372)
+++ django/trunk/django/core/management.py      2006-07-19 10:14:43 UTC (rev 
3373)
@@ -197,6 +197,7 @@
     data_types = get_creation_module().DATA_TYPES
 
     final_output = []
+    reference_names = {}
     if backend.supports_constraints:
         opts = klass._meta
         if klass in pending_references:
@@ -206,9 +207,14 @@
                 r_col = f.column
                 table = opts.db_table
                 col = opts.get_field(f.rel.field_name).column
+                r_name = '%s_referencing_%s_%s' % (r_col, table, col)
+                if r_name in reference_names:
+                    reference_names[r_name] += 1
+                    r_name += '_%s' % reference_names[r_name]
+                else:
+                    reference_names[r_name] = 0
                 final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s 
ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
-                    (backend.quote_name(r_table),
-                    backend.quote_name('%s_referencing_%s_%s' % (r_col, table, 
col)),
+                    (backend.quote_name(r_table), r_name,
                     backend.quote_name(r_col), backend.quote_name(table), 
backend.quote_name(col)))
             del pending_references[klass]
     return final_output


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---

Reply via email to