Commits

Anonymous committed 52120b0

Fixed issue #776 (http://south.aeracode.org/ticket/776) by using django.db.backends.creation.BaseDatabaseCreation._digest. Seems that it's better than copy and paste of _digest method from Dajngo code.

Comments (0)

Files changed (1)

south/db/generic.py

 from django.db import transaction, models
 from django.db.utils import DatabaseError
 from django.db.backends.util import truncate_name
+from django.db.backends.creation import BaseDatabaseCreation
 from django.db.models.fields import NOT_PROVIDED
 from django.dispatch import dispatcher
 from django.conf import settings
         return list(self._constraints_affecting_columns(
                     table_name, [column_name], "FOREIGN KEY"))
 
+    def _digest(self, *args):
+        """
+        Use django.db.backends.creation.BaseDatabaseCreation._digest
+        to create index name in Django style. An evil hack :(
+        """
+        if not hasattr(self, '_django_db_creation'):
+            self._django_db_creation = BaseDatabaseCreation(self._get_connection())
+        return self._django_db_creation._digest(*args)
+
     def create_index_name(self, table_name, column_names, suffix=""):
         """
         Generate a unique name for the index
         """
 
+        # If there is just one column in the index, use a default algorithm from Django
+        if len(column_names) == 1:
+            return truncate_name(
+                '%s_%s' % (table_name, self._digest(column_names[0])),
+                self._get_connection().ops.max_name_length()
+            )
+
+        # Else generate the name for the index by South
         table_name = table_name.replace('"', '').replace('.', '_')
-        index_unique_name = ''
-
-        if len(column_names) > 1:
-            index_unique_name = '_%x' % abs(hash((table_name, ','.join(column_names))))
+        index_unique_name = '_%x' % abs(hash((table_name, ','.join(column_names))))
 
         # 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('.', '_')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.