本文介绍了TransactionManagementError?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,感谢您的阅读.我正在Django中建立一个快速站点,并且在我对Postgres数据库进行的原始SQL中有一个非常简单的更新语句.这里有些麻烦了:
Hello thanks for reading. I am doing a quick site in Django and I have a very simple update statement in raw SQL I am making to my Postgres database. Something in here is making trouble:
from django.http import HttpResponse
from django.db import connection, transaction
def rsvp_update(request, rsvp_id, status):
cursor = connection.cursor()
cursor.execute("UPDATE public.rsvp SET status=%s WHERE rsvp_id = %s", [status, rsvp_id])
transaction.commit()
return HttpResponse('okay')
我收到一个错误消息,指出"[URL]上的"TransactionManagementError"该代码不在事务管理之下."有什么想法吗?
I am getting an error that says "TransactionManagementError at [URL]This code isn't under transaction management". Any ideas?
推荐答案
您需要使用 commit_manually
装饰器,用于您手动管理交易的代码.
You need to use the commit_manually
decorator for the code where you manage transactions manually.
这篇关于TransactionManagementError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!