
from django.db import transactiondef mysql():with transaction.atomic(): # 显式的开启一个事务save_id = transaction.savepoint() # 创建事务保存点try:except Exception as e:logger.error(e)transaction.savepoint_rollback(save_id) # 回滚transaction.savepoint_commit(save_id) # 提交订单成功,显式的提交一次事务