diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 59db3220fd..c0a82460cf 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -654,9 +654,6 @@ class BaseDatabaseFeatures(object): # Can we issue more than one ALTER COLUMN clause in an ALTER TABLE? supports_combined_alters = False - # What's the maximum length for index names? - max_index_name_length = 63 - # Does it support foreign keys? supports_foreign_keys = True diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 2495986a02..b86cc03446 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -99,7 +99,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): supports_sequence_reset = False atomic_transactions = False supports_combined_alters = False - max_index_name_length = 30 nulls_order_largest = True requires_literal_defaults = True connection_persists_old_columns = True diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py index 88cc894437..4a3d7fe46c 100644 --- a/django/db/backends/schema.py +++ b/django/db/backends/schema.py @@ -769,17 +769,18 @@ class BaseDatabaseSchemaEditor(object): # Else generate the name for the index using a different algorithm table_name = model._meta.db_table.replace('"', '').replace('.', '_') index_unique_name = '_%x' % abs(hash((table_name, ','.join(column_names)))) + max_length = self.connection.ops.max_name_length() or 200 # If the index name is too long, truncate it index_name = ('%s_%s%s%s' % (table_name, column_names[0], index_unique_name, suffix)).replace('"', '').replace('.', '_') - if len(index_name) > self.connection.features.max_index_name_length: + if len(index_name) > max_length: part = ('_%s%s%s' % (column_names[0], index_unique_name, suffix)) - index_name = '%s%s' % (table_name[:(self.connection.features.max_index_name_length - len(part))], part) + index_name = '%s%s' % (table_name[:(max_length - len(part))], part) # It shouldn't start with an underscore (Oracle hates this) if index_name[0] == "_": index_name = index_name[1:] # If it's STILL too long, just hash it down - if len(index_name) > self.connection.features.max_index_name_length: - index_name = hashlib.md5(force_bytes(index_name)).hexdigest()[:self.connection.features.max_index_name_length] + if len(index_name) > max_length: + index_name = hashlib.md5(force_bytes(index_name)).hexdigest()[:max_length] # It can't start with a number on Oracle, so prepend D if we need to if index_name[0].isdigit(): index_name = "D%s" % index_name[:-1]