心理上的错误,不管是什么

2024-09-11 00:46:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Django,只删除并重新创建数据库,以便刷新表数据。现在,当我尝试执行任何与数据库相关的任务时,我会得到:

./manage.py sql portfolio
Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_manager(settings)
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 362, in execute_manager
    utility.execute()
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 303, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/pymodules/python2.6/django/core/management/base.py", line 195, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/pymodules/python2.6/django/core/management/base.py", line 222, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/pymodules/python2.6/django/core/management/base.py", line 286, in handle
    app_output = self.handle_app(app, **options)
  File "/usr/lib/pymodules/python2.6/django/core/management/commands/sql.py", line 10, in handle_app
    return u'\n'.join(sql_create(app, self.style)).encode('utf-8')
  File "/usr/lib/pymodules/python2.6/django/core/management/sql.py", line 28, in sql_create
    tables = connection.introspection.table_names()
  File "/usr/lib/pymodules/python2.6/django/db/backends/__init__.py", line 491, in table_names
    return self.get_table_list(cursor)
  File "/usr/lib/pymodules/python2.6/django/db/backends/postgresql/introspection.py", line 30, in get_table_list
    AND pg_catalog.pg_table_is_visible(c.oid)""")
  File "/usr/lib/pymodules/python2.6/django/db/backends/util.py", line 19, in execute
    return self.cursor.execute(sql, params)
psycopg2.InternalError: BŁĄD:  current transaction is aborted, commands ignored until end of transaction block

正如您所看到的,这只是代码生成,所以事务应该不会有任何问题。发生什么事?:-(


Tags: djangoinpycoreselfappexecutesql
2条回答

这个错误意味着Postgres进程发生了一些事情,导致它在事务处理过程中失败,但事务从未提交或回滚,因此它被卡住了。在

基本上,您需要发出rollback命令(这通常可以从djangoshell完成),或者终止postgres进程。在

请注意(取决于您的服务器配置),即使Django没有,Postgres进程也会继续运行,因此每次都会遇到相同的错误,因为它可能仍然停留在同一个进程中。在

如果你已经这样做了,而且每次都是还是那么这意味着你在某个地方触发了实际代码中的错误,需要继续挖掘。在

检查postgres日志文件,查看导致数据库错误的实际查询。并尝试查找django的哪个部分进行此查询。在

还可以查看https://github.com/django-debug-toolbar/django-debug-toolbar/issues/351。 它说django调试工具栏可能是这个错误的原因。尝试禁用它。在

相关问题 更多 >