django / postgresql当前事务被中止,命令被忽略直到事务块结束

时间:2013-10-16 20:17:04

标签: django postgresql django-models

我收到了上述错误,当我提交模型表单时,我尝试了 -

1

from django.db import transaction
transaction.rollback()

2

from django import db
from django.db.backends.util import CursorDebugWrapper
old_execute = CursorDebugWrapper.execute
old_execute_many = CursorDebugWrapper.executemany

def execute_wrapper(*args, **kwargs):
    try:
        old_execute(*args, **kwargs)
    except Exception, ex:
        logger.error("Database error:\n%s" % ex)
        db.close_connection

def excecute_many_wrapper(*args, **kwargs):
    try:
        old_execute_many(*args, **kwargs)
    except Exception, ex:
        logger.error("Database error:\n%s" % ex)
        db.close_connection

CursorDebugWrapper.execute = execute_wrapper
CursorDebugWrapper.executemany = excecute_many_wrapper

3

from django.db import connection
connection._rollback()

4

manage.py migrate 

manage.py syncdb

然后重新提交模型表单,似乎再也没有发生。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您需要显示postgresql日志以找出问题所在,SQL查询错误。

tail -f /var/lib/pgsql/data/pg_log/postgresql-Thu.log