Commit 9c4ad454 authored by Andrew Godwin's avatar Andrew Godwin
Browse files

Fixed #21842: Remove redundant DatabaseFeatures.max_index_name_length

parent d5df7a05
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -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

+0 −1
Original line number Diff line number Diff line
@@ -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
+5 −4
Original line number Diff line number Diff line
@@ -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]