首页 > 代码库 > django 事务错误 -- Transaction managed block ended with pending COMMIT/ROLLBACK

django 事务错误 -- Transaction managed block ended with pending COMMIT/ROLLBACK

1 Request Method:    GET2 Request URL:    http://192.168.128.111:8000/×××/××××/3 Django Version:    1.4.84 Exception Type:    TransactionManagementError5 Exception Value:    6 Transaction managed block ended with pending COMMIT/ROLLBACK

今天在做事务处理的时候老是出现这个问题,我研究了半天,发现我代码严格按照

try:

  ***

exception:

  ***

else:

  ***

这种格式来写的,为什么还有错呢?

于是各种google,什么注释掉@transaction.commit_manually 看看错误在哪,什么都试了。

直到我找到这篇文章:http://stackoverflow.com/questions/9955321/django-transaction-managed-block-ended-with-pending-commit-rollback

马但啊,原来在返回视图前还有数据库操作。

1         retval = render_to_response(***/***.html,{2                 form:form,3                 nav_active:active,4             },context)5         transaction.commit()6         return retval

这样就OK了。

django 事务错误 -- Transaction managed block ended with pending COMMIT/ROLLBACK