Django:通过原因添加m2m,导致“当前事务被中止,命令被忽略,直到事务块结束”

时间:2022-07-15 22:49:39

I am trying to add an m2m relationship via a through table and, out of the blue, am encountering the following error:

我试图通过一个通过表格来增加一个m2m的关系,并且,从蓝色中,我遇到了以下错误:

'current transaction is aborted, commands ignored until end of transaction block'

“当前事务被中止,命令被忽略,直到事务块结束”

There are 2 odd issues about this. The first is that, I've successfully migrated/synced all of my relevant apps. The second is that both the associated models and the model in question (AddedFeature) successfully save into the database even if the error is thrown. That is, even though the transaction is aborted, the AddedFeature instance is saved to the DB.

关于这个有两个奇怪的问题。首先,我已经成功地迁移/同步了所有相关的应用。第二,即使抛出错误,关联的模型和相关的模型(AddedFeature)也能成功地保存到数据库中。也就是说,即使事务被中止,AddedFeature实例也被保存到DB中。

http://dpaste.com/1357120/

http://dpaste.com/1357120/

Just to reiterate - refreshing my DB and remigrating/resyncing did not help solve the issue.

重申一下——刷新我的数据库和重新运行/重新同步并没有帮助解决这个问题。

1 个解决方案

#1


1  

Look for the problem that happened before this error. Your code, or code you're using, is ignoring a database error. So the next operation fails.

查找这个错误之前发生的问题。您的代码或正在使用的代码正在忽略数据库错误。所以下一个操作失败了。

You need to look in the database and/or application logs to find the previous problem. Then determine what part of your app's code is swallowing a database exception without logging it and aborting the transaction.

您需要在数据库和/或应用程序日志中查找前面的问题。然后确定您的应用程序代码的哪个部分正在吞掉一个数据库异常,而不记录它并中止事务。

Setting log_statement = 'all' in postgresql.conf can be useful for this.

在postgresql中设置log_statement = 'all'。conf在这方面很有用。

#1


1  

Look for the problem that happened before this error. Your code, or code you're using, is ignoring a database error. So the next operation fails.

查找这个错误之前发生的问题。您的代码或正在使用的代码正在忽略数据库错误。所以下一个操作失败了。

You need to look in the database and/or application logs to find the previous problem. Then determine what part of your app's code is swallowing a database exception without logging it and aborting the transaction.

您需要在数据库和/或应用程序日志中查找前面的问题。然后确定您的应用程序代码的哪个部分正在吞掉一个数据库异常,而不记录它并中止事务。

Setting log_statement = 'all' in postgresql.conf can be useful for this.

在postgresql中设置log_statement = 'all'。conf在这方面很有用。