1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Fixed #21497 -- Forced conversion to bytes for very long index names

This commit is contained in:
Joel Bohman
2013-11-22 23:31:50 +01:00
committed by Tim Graham
parent f88e760869
commit 19e5cd77f0
4 changed files with 32 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ from django.db.backends.creation import BaseDatabaseCreation
from django.db.backends.utils import truncate_name
from django.db.models.fields.related import ManyToManyField
from django.db.transaction import atomic
from django.utils.encoding import force_bytes
from django.utils.log import getLogger
from django.utils.six.moves import reduce
from django.utils.six import callable
@@ -703,7 +704,7 @@ class BaseDatabaseSchemaEditor(object):
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(index_name).hexdigest()[:self.connection.features.max_index_name_length]
index_name = hashlib.md5(force_bytes(index_name)).hexdigest()[:self.connection.features.max_index_name_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]