python脚本更新数据库报错:pymysql.err.InternalError: (1054, u\"Unknown column '\\u533b\\u836f' in 'where clause'\")

别说谁变了你拦得住时间么 提交于 2020-02-04 22:58:59

这个错误让我很方啊。首先我的字段类型是用utf8mb4_unicode_ci编码的,防止emoji之类的显示不出来嘛,虽然说不会有emoji出现吧。

name = ['军事', '科幻', '美食', '散文', '童话', '政治', '哲学']
for na in name:
    a = random.randint(2, 5)
    #print type(a)
    con.execute("update b set maxstore=(%d) where bk=%s"%(a, na))
    con.execute("update b set rest=(%d) where bk=%s"%(a, na))
'''
a = random.randint(2, 5)
con.execute("update b set maxstore=(%d) where bk='医药'"%(a))
con.execute("update b set rest=(%d) where bk='医药'"%(a))
'''

没加注释的是报错的,加了注释的是正确的,就是为了省时才写的脚本,结果呵呵了,这两种方式有啥区别吗?为啥上边的就不对呢?有待研究。。。

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

11.16 问题解决:

bk = u'美食'
con.execute("use librarysystem")   
con.execute("select * from b where bk='"+bk+"'")
ans = con.fetchall()
if ans:
    print(ans)
    print(ans[0][0])

这样就可以了。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!