'will rename the table and an associated ID sequence and primary key index'

@generic.invalidate_table_constraints
def rename_table(self, old_table_name, table_name):

    generic.DatabaseOperations.rename_table(self, old_table_name, table_name)
    if self.execute('\n                                                SELECT    1\n                                                FROM    information_schema.sequences\n                                                WHERE    sequence_name    =    %s\n                                                ', [(old_table_name + '_id_seq')]):
        generic.DatabaseOperations.rename_table(self, (old_table_name + '_id_seq'), (table_name + '_id_seq'))
    pkey_index_names = self.execute('\n                                                SELECT    pg_index.indexrelid::regclass\n                                                FROM    pg_index,    pg_attribute\n                                                WHERE\n                                                        indrelid    =    %s::regclass    AND\n                                                        pg_attribute.attrelid    =    indrelid    AND\n                                                        pg_attribute.attnum    =    any(pg_index.indkey)\n                                                        AND    indisprimary\n                                                ', [table_name])
    if ((old_table_name + '_pkey') in pkey_index_names):
        generic.DatabaseOperations.rename_table(self, (old_table_name + '_pkey'), (table_name + '_pkey'))
