gpt4 book ai didi

django/postgres : Transaction managed block ended with pending COMMIT/ROLLBACK

转载 作者:行者123 更新时间:2023-11-29 13:06:58 28 4
gpt4 key购买 nike

我想运行 manage.py sqldiff myapp(来自 django 扩展的命令),但出现以下错误:

Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django_extensions/management/commands/sqldiff.py", line 596, in handle
sqldiff_instance.find_differences()
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 222, in inner
self.__exit__(None, None, None)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 207, in __exit__
self.exiting(exc_value, self.using)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 302, in exiting
leave_transaction_management(using=using)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 56, in leave_transaction_management
connection.leave_transaction_management()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 115, in leave_transaction_management
raise TransactionManagementError("Transaction managed block ended with "
django.db.transaction.TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK

manage.py runserver、shell、shell_plus 都工作正常,但 sqldiff 命令卡住了。我试过:

  • restart postgres server
  • manually connect to postgres from shell via psycopg2, ran connection.rollback(), and connection.commit()

但错误仍然存​​在。

欢迎提出任何关于可以做什么的想法!

干杯,

霍夫

最佳答案

我更新了一个 issue使用 sqldiff 导致类似的问题。你最好的选择可能是从 github repository 获得 django-extensions|并做一些调查。编辑 sqldiff.py 并注释掉修饰 find_differences 方法的事务代码:

#    @transaction.commit_manually
def find_differences(self):
...
# transaction.rollback() # reset transaction
...
# transaction.commit()

现在您真正的问题应该暴露出来,不再被事务异常所掩盖。

关于django/postgres : Transaction managed block ended with pending COMMIT/ROLLBACK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7042463/

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