summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2012-09-24 13:23:25 +0100
committerAndrew Godwin <andrew@aeracode.org>2012-09-24 13:23:25 +0100
commit0bcfc068b011c41aeed135649276106147d90d70 (patch)
tree844f4994aef4c644cb0d057b4f047377afe875fc
parentd146b250aecd7adb13ad7b998cc60cc3a10fd0b6 (diff)
Add second shortener to create_index_name for very long columns
-rw-r--r--django/db/backends/schema.py4
1 files changed, 4 insertions, 0 deletions
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):