SQLAlchemy IntegrityError:但是哪条记录?

时间:2018-06-05 19:59:59

标签: python sqlite sqlalchemy

在我的程序中,我使用的是executemany-operation。好吧,它工作正常,但如果数据库中已经存在记录,我会得到IntegrityError异常。这很好,也很正确。但我不知道哪条记录现在加倍。我想我无法正确解释Traceback。

>   File
> "D:\Dan\Python\Xarphus\xarphus\subclass_master_data_load_data_item.py",
> line 358, in _bulk_save_list_records
>     master_data_manipulation.add_record(bulk_list = list_records, category = category, work_area = work_area)   File
> "D:\Dan\Python\Xarphus\xarphus\core\manage_data_manipulation_master_data.py",
> line 393, in add_record
>     self._session.bulk_save_objects(object_list)   File "build\bdist.win32\egg\sqlalchemy\orm\session.py", line 2372, in
> bulk_save_objects
>     return_defaults, update_changed_only, False)   File "build\bdist.win32\egg\sqlalchemy\orm\session.py", line 2536, in
> _bulk_save_mappings
>     transaction.rollback(_capture_exception=True)   File "build\bdist.win32\egg\sqlalchemy\util\langhelpers.py", line 66, in
> __exit__
>     compat.reraise(exc_type, exc_value, exc_tb)   File "build\bdist.win32\egg\sqlalchemy\orm\session.py", line 2531, in
> _bulk_save_mappings
>     isstates, return_defaults, render_nulls)   File "build\bdist.win32\egg\sqlalchemy\orm\persistence.py", line 69, in
> _bulk_insert
>     bookkeeping=return_defaults)   File "build\bdist.win32\egg\sqlalchemy\orm\persistence.py", line 799, in
> _emit_insert_statements
>     execute(statement, multiparams)   File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 945, in
> execute
>     return meth(self, multiparams, params)   File "build\bdist.win32\egg\sqlalchemy\sql\elements.py", line 263, in
> _execute_on_connection
>     return connection._execute_clauseelement(self, multiparams, params)   File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line
> 1053, in _execute_clauseelement
>     compiled_sql, distilled_params   File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 1189, in
> _execute_context
>     context)   File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 1402, in _handle_dbapi_exception
>     exc_info   File "build\bdist.win32\egg\sqlalchemy\util\compat.py", line 203, in raise_from_cause
>     reraise(type(exception), exception, tb=exc_tb, cause=cause)   File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 1159, in
> _execute_context
>     context)   File "build\bdist.win32\egg\sqlalchemy\engine\default.py", line 467, in
> do_executemany
>     cursor.executemany(statement, parameters) IntegrityError: (sqlite3.IntegrityError) column genre is not unique [SQL: u'INSERT
> INTO music_genre (genre) VALUES (?)'] [parameters: ((u'\ufeffGlitch
> Pop',), (u'Shoegaze',), (u'Tango',), (u'Bitpop and Chiptune',),
> (u"R'n'B",), (u'Hard Bop',), (u'Afro Punk',), (u'Irish Rock',)  ...
> displaying 10 of 746 total bound parameter sets ...  (u'Roots',),
> (u'Alternative Rap',))]

0 个答案:

没有答案