pymysql 插入数据时出现pymysql.err.DataError

今天在用pymysql插入数据时出现一下异常。

Traceback (most recent call last):
  File "/Users/lx/PycharmProjects/AWS/AWS_DATA/MWS.py", line 340, in save_data
    self.mysql.insertOne(sql, temp)
  File "/Users/lx/PycharmProjects/AWS/db_mysql/_pool.py", line 103, in insertOne
    self._cursor.execute(sql,value)
  File "/Users/lx/PycharmProjects/AWS/venv/lib/python3.8/site-packages/DBUtils/SteadyDB.py", line 605, in tough_method
    result = method(*args, **kwargs)  # try to execute
  File "/Users/lx/PycharmProjects/AWS/venv/lib/python3.8/site-packages/pymysql/cursors.py", line 163, in execute
    result = self._query(query)
  File "/Users/lx/PycharmProjects/AWS/venv/lib/python3.8/site-packages/pymysql/cursors.py", line 321, in _query
    conn.query(q)
  File "/Users/lx/PycharmProjects/AWS/venv/lib/python3.8/site-packages/pymysql/connections.py", line 505, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/Users/lx/PycharmProjects/AWS/venv/lib/python3.8/site-packages/pymysql/connections.py", line 724, in _read_query_result
    result.read()
  File "/Users/lx/PycharmProjects/AWS/venv/lib/python3.8/site-packages/pymysql/connections.py", line 1069, in read
    first_packet = self.connection._read_packet()
  File "/Users/lx/PycharmProjects/AWS/venv/lib/python3.8/site-packages/pymysql/connections.py", line 676, in _read_packet
    packet.raise_for_error()
  File "/Users/lx/PycharmProjects/AWS/venv/lib/python3.8/site-packages/pymysql/protocol.py", line 223, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "/Users/lx/PycharmProjects/AWS/venv/lib/python3.8/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.DataError: (1264, "Out of range value for column 'your-price' at row 1")

后来检查数据发现your-price列对应的数据为float,长度为5,而数值为3952.0,确定数据长度过小,修改数据库对应字段长度之后解决问题。

你可能感兴趣的:(pymysql 插入数据时出现pymysql.err.DataError)