python脚本更新数据库报错:pymysql.err.InternalError: (1054, u"Unknown column '\u533b\u836f' in 'where clause'")
这个错误让我很方啊。首先我的字段类型是用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])
这样就可以了。