
from django.db import connection
from south.db import generic

class DatabaseOperations(generic.DatabaseOperations):

    """
    PsycoPG2 implementation of database operations.
    """

    def rename_column(self, table_name, old, new):
        if old == new:
            return []
        qn = connection.ops.quote_name
        params = (qn(table_name), qn(old), qn(new))
        self.execute('ALTER TABLE %s RENAME COLUMN %s TO %s;' % params)
    
    def rename_table(self, old_table_name, table_name):
        # First, rename the table
        generic.DatabaseOperations.rename_table(self, old_table_name, table_name)
        # Then, try renaming the ID sequence
        # (if you're using other AutoFields... your problem, unfortunately)
        self.commit_transaction()
        self.start_transaction()
        try:
            generic.DatabaseOperations.rename_table(self, old_table_name+"_id_seq", table_name+"_id_seq")
        except:
            print "   ~ No such sequence (ignoring error)"
            self.rollback_transaction()
        else:
            self.commit_transaction()
        self.start_transaction()
@@ -501,16 +501,100 @@
 _name):%0A
+        %22will rename the table and an associated ID sequence and primary key index%22%0A
         
@@ -619,16 +619,16 @@
 e table%0A
-
         
@@ -1024,16 +1024,47 @@
 except:%0A
+            if self.debug:%0A    
         
@@ -1114,16 +1114,16 @@
 error)%22%0A
-
         
@@ -1198,32 +1198,32 @@
 t_transaction()%0A
-
         self.sta
@@ -1218,28 +1218,755 @@
     self.start_transaction()
+%0A%0A        # Rename primary key index, will not rename other indices on%0A        # the table that are used by django (e.g. foreign keys). Until%0A        # figure out how, you need to do this yourself.%0A        try:%0A            generic.DatabaseOperations.rename_table(self, old_table_name+%22_pkey%22, table_name+ %22_pkey%22)%0A        except:%0A            if self.debug:%0A                print %22   ~ No such primary key (ignoring error)%22%0A            self.rollback_transaction()%0A        else:%0A            self.commit_transaction()%0A        self.start_transaction()%0A%0A%0A    def rename_index(self, old_index_name, index_name):%0A        %22Rename an index individually%22%0A        generic.DatabaseOperations.rename_table(self, old_index_name, index_name)%0A

Rename primary key index with table