首页 > 代码库 > pymysql.err.InternalError: (1054, "Unknown column 'None' in 'field list'")

pymysql.err.InternalError: (1054, "Unknown column 'None' in 'field list'")

技术分享

错误提示:

Traceback (most recent call last):  File "D:/projectwc/test/dd.py", line 43, in <module>    effect_row = cursor.execute("insert into `222` set c={}".format(None))  File "C:\python\lib\site-packages\pymysql\cursors.py", line 166, in execute    result = self._query(query)  File "C:\python\lib\site-packages\pymysql\cursors.py", line 322, in _query    conn.query(q)  File "C:\python\lib\site-packages\pymysql\connections.py", line 835, in query    self._affected_rows = self._read_query_result(unbuffered=unbuffered)  File "C:\python\lib\site-packages\pymysql\connections.py", line 1019, in _read_query_result    result.read()  File "C:\python\lib\site-packages\pymysql\connections.py", line 1302, in read    first_packet = self.connection._read_packet()  File "C:\python\lib\site-packages\pymysql\connections.py", line 981, in _read_packet    packet.check_error()  File "C:\python\lib\site-packages\pymysql\connections.py", line 393, in check_error    err.raise_mysql_exception(self._data)  File "C:\python\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception    raise errorclass(errno, errval)pymysql.err.InternalError: (1054, "Unknown column ‘None‘ in ‘field list‘")
import pymysql# 创建连接conn = pymysql.connect(host=192.168.72.135, port=3306, user=root, passwd=123456, db=test)# 创建游标cursor = conn.cursor()# 执行SQL,并返回收影响行数effect_row = cursor.execute("insert into `222` set c={}".format(None))# 提交,不然无法保存新建或者修改的数据conn.commit()# 关闭游标cursor.close()# 关闭连接conn.close()

 

 解决办法:

把None 换成“Null”

effect_row = cursor.execute("insert into `222` set c={}".format("Null"))

 

pymysql.err.InternalError: (1054, "Unknown column 'None' in 'field list'")