Andrew Godwin avatar Andrew Godwin committed ecea303

Give unique constraints different names to indexes.

Comments (0)

Files changed (1)

south/db/generic.py

         if not isinstance(columns, (list, tuple)):
             columns = [columns]
         
-        name = self.create_index_name(table_name, columns)
+        name = self.create_index_name(table_name, columns, suffix="_uniq")
         
         cols = ", ".join(map(qn, columns))
         self.execute("ALTER TABLE %s ADD CONSTRAINT %s UNIQUE (%s)" % (qn(table_name), qn(name), cols))
     drop_foreign_key = alias('delete_foreign_key')
 
     
-    def create_index_name(self, table_name, column_names):
+    def create_index_name(self, table_name, column_names, suffix=""):
         """
         Generate a unique name for the index
         """
             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' % (table_name, column_names[0], index_unique_name))
+        index_name = ('%s_%s%s%s' % (table_name, column_names[0], index_unique_name, suffix))
         if len(index_name) > self.max_index_name_length:
-            part = ('_%s%s' % (column_names[0], index_unique_name))
-            index_name = '%s%s' % (table_name[:(self.max_index_name_length-len(part))], part)
+            part = ('_%s%s%s' % (column_names[0], index_unique_name, suffix))
+            index_name = '%s%s%s' % (table_name[:(self.max_index_name_length-len(part))], part)
         
         return index_name
 
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.