我在 SQL Server 表中使用了反射的 sqlalchemy 映射类。我的活动类(映射类)的 DBSession.add() 实例包含从不同来源获得的数据。然后我调用了 transaction.commit()(因为我是从 tg2 调用的,所以我不能使用 session.commit())
错误回溯:
DataError: (DataError) ('22001', '[22001] [Microsoft][ODBC SQL Server Driver][SQ
L Server]String or binary data would be truncated. (8152) (SQLExecDirectW); [010
00] [Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been termin
ated. (3621)') u'INSERT INTO [NOAR_LOADEVENTS] ([EVENTCODE]) VALUES (?)' ((u'210
401',), (u'210402',), (u'210602',), (u'210603',), (u'000010',), (u'000102',), (u
'000206',), (u'000107',) ... displaying 10 of 49 total bound parameter sets ...
(u'211302',), (u'210403',))
很高兴得到任何帮助,因为我不知道如何从这里继续/调试
编辑:我怀疑这与 unicode 有关,所以我将 sqlalchemy 列更改为 unicode。
也许 DataError 以某种方式卡住了,我需要调用回滚,但我不知道在 tg2 的事务中调用回滚是热的
编辑:mssql 中的 EVENTCODE 列是:datatype:PK,nvarchar(6),不为空希望这有帮助
另一个编辑:插入代码(相关部分)
event = #json with data
ac['EVENTCODE']=event.get('code')#for example u'210602' - from the failing data
...
...
e = Activities(**ac) # this is the class mapped with sqlalchemy to the NOAR_LOADEVENTS in sqlalchemy.
DBSession2.add(e)
transaction.commit()