TransactionManagementError("An error occurred in the current transaction. You can't execute queries

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014686399/article/details/78310374

在写一个测试用例的时候,一直报:TransactionManagementError("An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block这个错,整的我头都大了,整了一天才找到办法。大哭

==================================================================================================================================

(1)首先,前提我这是在写测试的时候报的错。

(2)我的测试:

就是需要一个事务添加一条数据。然后另一个事务删除这条数据。

(3)报错:

TransactionManagementError("An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block发火

4解决办法:

我的测试用例定义的时候开始继承的是TestCase ,运行的时候 添加数据成功,但是删除数据的时候就会报上面的错,

    把的类改为TransactionTestCase,就可以正常运行了。

(5)参考文章:

http://blog.csdn.net/ysjian_pingcx/article/details/51015988

https://docs.djangoproject.com/en/dev/topics/db/transactions/


猜你喜欢

转载自blog.csdn.net/u014686399/article/details/78310374