问题
如图所示,错误返回结果是An error occurred in the current transaction. You can't execute queries until the end of the 'atomic block
(这个在django中,用swagger进行调试,自己捕获异常的结果)
分析
字面意思
就是django中从开启事务后,到事务with结束(包含异常)后,执行了数据查询语句。
我代码的基本结构(犯了最底下的两个要点)
class InfoStore(APIView):
@swagger_auto_schema(******)
def post(self, request):
receive_data = request.data
with transaction.atomic(): # 1 在transaction中去try except自己捕获异常
# 创建事务保存点
save_id = transaction.savepoint()
try:
if(InfoTest.objects.filter(**