xiadada2 2018-03-15 15:05 采纳率: 0%
浏览 3758
已结题

python提交commit()错误

图片说明
报错
C:\Python33\python.exe C:/Users/test/sql2.py
C:\Python33\lib\site-packages\pymysql\cursors.py:165: Warning: (1366, "Incorrect string value: '\xD6\xD0\xB9\xFA\xB1\xEA...' for column 'VARIABLE_VALUE' at row 480")
result = self._query(query)
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\sqlalchemy\engine\base.py", line 1193, in _execute_context
context)
File "C:\Python33\lib\site-packages\sqlalchemy\engine\default.py", line 507, in do_execute
cursor.execute(statement, parameters)
File "C:\Python33\lib\site-packages\pymysql\cursors.py", line 165, in execute
result = self._query(query)
File "C:\Python33\lib\site-packages\pymysql\cursors.py", line 321, in _query
conn.query(q)
File "C:\Python33\lib\site-packages\pymysql\connections.py", line 860, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "C:\Python33\lib\site-packages\pymysql\connections.py", line 1061, in _read_query_result
result.read()
File "C:\Python33\lib\site-packages\pymysql\connections.py", line 1349, in read
first_packet = self.connection._read_packet()
File "C:\Python33\lib\site-packages\pymysql\connections.py", line 1018, in _read_packet
packet.check_error()
File "C:\Python33\lib\site-packages\pymysql\connections.py", line 384, in check_error
err.raise_mysql_exception(self._data)
File "C:\Python33\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.IntegrityError: (1062, "Duplicate entry '7' for key 'PRIMARY'")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:/Users/test/sql2.py", line 25, in
session.commit()
File "C:\Python33\lib\site-packages\sqlalchemy\orm\session.py", line 937, in commit
self.transaction.commit()
File "C:\Python33\lib\site-packages\sqlalchemy\orm\session.py", line 461, in commit
self._prepare_impl()
File "C:\Python33\lib\site-packages\sqlalchemy\orm\session.py", line 441, in prepare_impl
self.session.flush()
File "C:\Python33\lib\site-packages\sqlalchemy\orm\session.py", line 2237, in flush
self._flush(objects)
File "C:\Python33\lib\site-packages\sqlalchemy\orm\session.py", line 2363, in _flush
transaction.rollback(_capture_exception=True)
File "C:\Python33\lib\site-packages\sqlalchemy\util\langhelpers.py", line 66, in __exit
_
compat.reraise(exc_type, exc_value, exc_tb)
File "C:\Python33\lib\site-packages\sqlalchemy\util\compat.py", line 187, in reraise
raise value
File "C:\Python33\lib\site-packages\sqlalchemy\orm\session.py", line 2327, in _flush
flush_context.execute()
File "C:\Python33\lib\site-packages\sqlalchemy\orm\unitofwork.py", line 391, in execute
rec.execute(self)
File "C:\Python33\lib\site-packages\sqlalchemy\orm\unitofwork.py", line 556, in execute
uow
File "C:\Python33\lib\site-packages\sqlalchemy\orm\persistence.py", line 181, in save_obj
mapper, table, insert)
File "C:\Python33\lib\site-packages\sqlalchemy\orm\persistence.py", line 830, in _emit_insert_statements
execute(statement, multiparams)
File "C:\Python33\lib\site-packages\sqlalchemy\engine\base.py", line 948, in execute
return meth(self, multiparams, params)
File "C:\Python33\lib\site-packages\sqlalchemy\sql\elements.py", line 269, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "C:\Python33\lib\site-packages\sqlalchemy\engine\base.py", line 1060, in _execute_clauseelement
compiled_sql, distilled_params
File "C:\Python33\lib\site-packages\sqlalchemy\engine\base.py", line 1200, in _execute_context
context)
File "C:\Python33\lib\site-packages\sqlalchemy\engine\base.py", line 1413, in _handle_dbapi_exception
exc_info
File "C:\Python33\lib\site-packages\sqlalchemy\util\compat.py", line 203, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "C:\Python33\lib\site-packages\sqlalchemy\util\compat.py", line 186, in reraise
raise value.with_traceback(tb)
File "C:\Python33\lib\site-packages\sqlalchemy\engine\base.py", line 1193, in _execute_context
context)
File "C:\Python33\lib\site-packages\sqlalchemy\engine\default.py", line 507, in do_execute
cursor.execute(statement, parameters)
File "C:\Python33\lib\site-packages\pymysql\cursors.py", line 165, in execute
result = self._query(query)
File "C:\Python33\lib\site-packages\pymysql\cursors.py", line 321, in _query
conn.query(q)
File "C:\Python33\lib\site-packages\pymysql\connections.py", line 860, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "C:\Python33\lib\site-packages\pymysql\connections.py", line 1061, in _read_query_result
result.read()
File "C:\Python33\lib\site-packages\pymysql\connections.py", line 1349, in read
first_packet = self.connection._read_packet()
File "C:\Python33\lib\site-packages\pymysql\connections.py", line 1018, in _read_packet
packet.check_error()
File "C:\Python33\lib\site-packages\pymysql\connections.py", line 384, in check_error
err.raise_mysql_exception(self._data)
File "C:\Python33\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
sqlalchemy.exc.IntegrityError: (pymysql.err.IntegrityError) (1062, "Duplicate entry '7' for key 'PRIMARY'") [SQL: 'INSERT INTO user (id, name) VALUES (%(id)s, %(name)s)'] parameters: {'id': '7', 'name': 'haha'}

进程已结束,退出代码1

虽然报错了,但数据库里还是插入了数据的

  • 写回答

4条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥100 如何用js写一个游戏云存档
  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥30 C++行情软件的tick数据如何高效的合成K线