我的环境是python2.7.3和django1.4.1
我将 MySQL 与 MyISAM 表一起使用。
我的测试代码:
from django.core.management import setup_environ
from myproject import settings
setup_environ(settings)
from myproject.models import *
from django.db import transaction
@transaction.commit_manually
def test_trans():
r=tab1.objects.get(no="1")
r.value=100
r.save()
transaction.rollback()#I already rollback here, but data is still being updated to the database
def main():
try:
test_trans()
except:
pass
if __name__ == '__main__':
main()
似乎 transaction.rollback() 没有回滚我的事务,因为数据仍在更新到数据库中。