diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2006-07-19 10:14:43 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2006-07-19 10:14:43 +0000 |
| commit | 0016547e9b29db789c416fab74f39561db4e75ef (patch) | |
| tree | 68d7ce14dba090989f265bef9e4ef1adb230a360 | |
| parent | ab4ffe5d78c9eb9cab1a15828dddf3c5f010ad2a (diff) | |
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
| -rw-r--r-- | django/core/management.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/django/core/management.py b/django/core/management.py index cc0c749dbe..561c6bc84d 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -197,6 +197,7 @@ def _get_sql_for_pending_references(klass, pending_references): 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 @@ def _get_sql_for_pending_references(klass, pending_references): 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 |
