'Remove a Unique Index from a table'

def remove_unique(self, tablename, fieldname):

    db = self.db
    db_engine = self.db_engine
    if (db_engine == 'sqlite'):
        raise NotImplementedError
    elif (db_engine == 'mysql'):
        sql = ('ALTER    TABLE    `%(tablename)s`    DROP    INDEX    `%(fieldname)s`;' % dict(tablename=tablename, fieldname=fieldname))
    elif (db_engine == 'postgres'):
        sql = ('ALTER    TABLE    %(tablename)s    DROP    CONSTRAINT    %(tablename)s_%(fieldname)s_key;' % dict(tablename=tablename, fieldname=fieldname))
    try:
        db.executesql(sql)
    except:
        import sys
        e = sys.exc_info()[1]
        print >>sys.stderr, e
    table = db[tablename]
    fields = []
    for fn in table.fields:
        field = table[fn]
        if (fn == fieldname):
            field.unique = False
        fields.append(field)
    db.__delattr__(tablename)
    db.tables.remove(tablename)
    db.define_table(tablename, fake_migrate=True, *fields)
