gpt4 book ai didi

python - 插入表时处理 SQLAlchemy 中的触发器

转载 作者:行者123 更新时间:2023-11-30 22:25:31 24 4
gpt4 key购买 nike

我已经使用flask-SQLAlchemy 映射数据库中名为Proposal 的表之一,但在从应用程序插入数据库时​​遇到了问题。这是错误:

sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000]

[Microsoft][ODBC SQL Server Driver][SQL Server]The target table 'Proposal' of
the DML statement cannot have any enabled triggers if the statement contain an
OUTPUT clause without INTO clause. (334) (SQLExecDirectW); [42000] [Microsoft]
[ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared

数据库是MSSQL类型。

SQLAlchemy生成的sql语句为

SQL: 'INSERT INTO [Proposal] (proposal_fee, contract1, contract,
proposal_disb, source, sid, value_per_hr, team_hrs, reason_for_loss,
incharge, [Country_id], [manner], [Manager_id], preparer_id,
task_id, date_received, proposal_deadline, industry_id,
proposal_currency_id, contract_currency_id, service_description_id,
business_unit_id, status_id, associated_cost) OUTPUT inserted.[ID] VALUE
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)']
[parameters: ('', '', '', '', '', 'None', '', '', None, 'Adv,
Office', 'Select Country', None, 'ABCD', 'some name', '1007000', '', '', '', '', 'usd', None, None, '', '')]

我知道当我禁用触发器时,插入将起作用,但我需要 sqlalchemy 中的一个解决方案来解决这个问题?

有什么办法吗?

最佳答案

我意识到我必须删除该输出子句,并找到了推荐使用的解决方案:

__table_args__ = {'implicit_returning':False}

为提案表创建类时。

关于python - 插入表时处理 SQLAlchemy 中的触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47513622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com