'Rename a field, while keeping the other properties of the field the same.
If there are some indexes on that table, these will be recreated and other constraints will remain unchanged too.
@param tablename          : name of the table in which the field is renamed
@param fieldname_old      : name of the original field before renaming
@param fieldname_new      : name of the field after renaming
@param attributes_to_copy : list of attributes which need to be copied from the old_field to the new_field (needed only in sqlite)'

def rename_field(self, tablename, fieldname_old, fieldname_new, attributes_to_copy=None):

    db = self.db
    db_engine = self.db_engine
    if (db_engine == 'sqlite'):
        self._add_renamed_fields(db, tablename, fieldname_old, fieldname_new, attributes_to_copy)
        self._copy_field(db, tablename, fieldname_old, fieldname_new)
        sql = ("SELECT    sql    FROM    sqlite_master    WHERE    type='index'    AND    tbl_name='%s'    ORDER    BY    name;" % tablename)
        list_index = db.executesql(sql)
        for element in list_index:
            search_str = ('%s(%s)' % (tablename, fieldname_old))
            if ((element[0] is not None) and (search_str in element[0])):
                sql = ('CREATE    INDEX    %s__idx    on    %s(%s);' % (fieldname_new, tablename, fieldname_new))
                try:
                    db.executesql(sql)
                except:
                    pass
    elif (db_engine == 'mysql'):
        field = db[tablename][fieldname_old]
        sql_type = map_type_web2py_to_sql(field.type)
        sql = ('ALTER    TABLE    %s    CHANGE    %s    %s    %s(%s)' % (tablename, fieldname_old, fieldname_new, sql_type, field.length))
        db.executesql(sql)
    elif (db_engine == 'postgres'):
        sql = ('ALTER    TABLE    %s    RENAME    COLUMN    %s    TO    %s;' % (tablename, fieldname_old, fieldname_new))
        db.executesql(sql)
