pymysql.err.InternalError: (1054, "Unknown column 'None' in 'field list'")
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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"))
还要注意字符串"Insert into 库.表 (`ID`, ....) values (123, \'Null\'), ()" 如果要空值需要在替换一下
sql = sql.replace("\'Null\'", "Null")
以上是关于pymysql.err.InternalError: (1054, "Unknown column 'None' in 'field list'")的主要内容,如果未能解决你的问题,请参考以下文章
pymysql.err.InternalError:(1049,“未知数据库”)
InternalError: (pymysql.err.InternalError) (1205, u'Lock wait timeout exceeded; try restarting t
pymysql.err.InternalError: (1054, "Unknown column 'None' in 'field list'")