Fixed #21842: Remove redundant DatabaseFeatures.max_index_name_length

This commit is contained in:
Andrew Godwin 2014-02-09 12:33:52 +00:00
parent d5df7a0515
commit 9c4ad454d1
3 changed files with 5 additions and 8 deletions

View File

@ -654,9 +654,6 @@ class BaseDatabaseFeatures(object):
# Can we issue more than one ALTER COLUMN clause in an ALTER TABLE? # Can we issue more than one ALTER COLUMN clause in an ALTER TABLE?
supports_combined_alters = False supports_combined_alters = False
# What's the maximum length for index names?
max_index_name_length = 63
# Does it support foreign keys? # Does it support foreign keys?
supports_foreign_keys = True supports_foreign_keys = True

View File

@ -99,7 +99,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
supports_sequence_reset = False supports_sequence_reset = False
atomic_transactions = False atomic_transactions = False
supports_combined_alters = False supports_combined_alters = False
max_index_name_length = 30
nulls_order_largest = True nulls_order_largest = True
requires_literal_defaults = True requires_literal_defaults = True
connection_persists_old_columns = True connection_persists_old_columns = True

View File

@ -769,17 +769,18 @@ class BaseDatabaseSchemaEditor(object):
# Else generate the name for the index using a different algorithm # Else generate the name for the index using a different algorithm
table_name = model._meta.db_table.replace('"', '').replace('.', '_') table_name = model._meta.db_table.replace('"', '').replace('.', '_')
index_unique_name = '_%x' % abs(hash((table_name, ','.join(column_names)))) 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 # 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('.', '_') 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)) 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) # It shouldn't start with an underscore (Oracle hates this)
if index_name[0] == "_": if index_name[0] == "_":
index_name = index_name[1:] index_name = index_name[1:]
# If it's STILL too long, just hash it down # If it's STILL too long, just hash it down
if len(index_name) > self.connection.features.max_index_name_length: if len(index_name) > max_length:
index_name = hashlib.md5(force_bytes(index_name)).hexdigest()[:self.connection.features.max_index_name_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 # It can't start with a number on Oracle, so prepend D if we need to
if index_name[0].isdigit(): if index_name[0].isdigit():
index_name = "D%s" % index_name[:-1] index_name = "D%s" % index_name[:-1]