def fix_name(inp, names_used):
    """Append a number if an autoSql field name is duplicated.
    """
    name = inp
    i = 2
    while name in names_used:
        name = "%s%s" % (inp, i)
        i += 1

    names_used.append(name)
    return name