Commits

Anonymous committed 0f06299

Keep PostgreSQL single-column index naming consistent.

Make the postgresql_psycopg2 backend use the same name for a single-column
index when creating or dropping it.

  • Participants
  • Parent commits 3e25c74

Comments (0)

Files changed (1)

File south/db/postgresql_psycopg2.py

-
-from django.db import connection, models
+from django.db.backends.util import truncate_name
 from south.db import generic
 
 class DatabaseOperations(generic.DatabaseOperations):
     
     backend_name = "postgres"
 
+    def create_index_name(self, table_name, column_names, suffix=""):
+        """
+        Generate a unique name for the index
+
+        Django's logic for naming field indexes is different in the
+        postgresql_psycopg2 backend, so we follow that for single-column
+        indexes.
+        """
+
+        if len(column_names) == 1:
+            return truncate_name(
+                '%s_%s' % (table_name, column_names[0]),
+                self._get_connection().ops.max_name_length()
+            )
+        return super(DatabaseOperations, self).create_index_name(table_name, column_names, suffix)
+
+
     @generic.copy_column_constraints
     @generic.delete_column_constraints
     def rename_column(self, table_name, old, new):