首页 > 怎样知道django数据库有没有操作成功?

怎样知道django数据库有没有操作成功?

from django.db import connection,transaction
cursor = connection.cursor()#获得一个游标(cursor)对象
cursor.execute('update other_other2 set name ="李四" where id=%s',[3])        
transaction.commit_unless_managed()#提交到数据库

我该怎么知道数据库有没有更新成功呢?


失败的话会抛出TransactionManagementError异常


直接从sql里提取刚刚更新的数据不就看到了么

【热门文章】
【热门文章】