pymysql.err.OperationalError: (1054, 'Unknown column
记一次数据库查询bug解决
使用pymysql 连接数据库进行查询,报错
原因是数据库字段中有引号,等特殊字符,导致拼写的sql 不能正确解析产生报错
# 原来的写法
sql = "select * from robot_chat_record where account='{}'".format(account))
# 新的写法, 一下两种都可以
sql = "select * from robot_chat_record where account={}".format(repr(account))
sql = "select * from robot_chat_record where account={a}".format(a=repr(account))