mirror of
https://github.com/django/django.git
synced 2025-10-25 06:36:07 +00:00
[boulder-oracle-sprint] Added truncate_name to ADD CONSTRAINT code
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@3976 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -214,6 +214,7 @@ def _get_sql_for_pending_references(model, pending_references):
|
|||||||
Get any ALTER TABLE statements to add constraints after the fact.
|
Get any ALTER TABLE statements to add constraints after the fact.
|
||||||
"""
|
"""
|
||||||
from django.db import backend, get_creation_module
|
from django.db import backend, get_creation_module
|
||||||
|
from django.db.backend.util import truncate_name
|
||||||
data_types = get_creation_module().DATA_TYPES
|
data_types = get_creation_module().DATA_TYPES
|
||||||
|
|
||||||
final_output = []
|
final_output = []
|
||||||
@@ -229,15 +230,9 @@ def _get_sql_for_pending_references(model, pending_references):
|
|||||||
# For MySQL, r_name must be unique in the first 64 characters.
|
# For MySQL, r_name must be unique in the first 64 characters.
|
||||||
# So we are careful with character usage here.
|
# So we are careful with character usage here.
|
||||||
r_name = '%s_refs_%s_%x' % (r_col, col, abs(hash((r_table, table))))
|
r_name = '%s_refs_%s_%x' % (r_col, col, abs(hash((r_table, table))))
|
||||||
# if constraint name size is over 29 char and db is oracle, chop it
|
final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
|
||||||
if settings.DATABASE_ENGINE == 'oracle' and len(r_name) > 29:
|
(backend.quote_name(r_table), truncate_name(r_name, backend.get_max_name_length()),
|
||||||
final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
|
backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col)))
|
||||||
(backend.quote_name(r_table), r_name[0:29],
|
|
||||||
backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col)))
|
|
||||||
else:
|
|
||||||
final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
|
|
||||||
(backend.quote_name(r_table), r_name,
|
|
||||||
backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col)))
|
|
||||||
del pending_references[model]
|
del pending_references[model]
|
||||||
return final_output
|
return final_output
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user