From 0bcfc068b011c41aeed135649276106147d90d70 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Mon, 24 Sep 2012 13:23:25 +0100 Subject: [PATCH] Add second shortener to create_index_name for very long columns --- django/db/backends/schema.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py index 08b53e7cb2..a9e069aa7b 100644 --- a/django/db/backends/schema.py +++ b/django/db/backends/schema.py @@ -1,3 +1,4 @@ +import hashlib from django.db.backends.creation import BaseDatabaseCreation from django.db.backends.util import truncate_name from django.utils.log import getLogger @@ -615,6 +616,9 @@ class BaseDatabaseSchemaEditor(object): if len(index_name) > self.connection.features.max_index_name_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) + # 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(index_name).hexdigest()[:self.connection.features.max_index_name_length] return index_name def _constraint_names(self, model, column_names=None, unique=None, primary_key=None, index=None, foreign_key=None, check=None):