gpt4 book ai didi

python - Django 测试失败,内部错误 : no such savepoint. DB : Postgres, 通过 mysql

转载 作者:可可西里 更新时间:2023-11-01 07:07:35 30 4
gpt4 key购买 nike

有趣的是,它也适用于 shell。

   [MY code which calls Model.objects.get_or_create(...)]
File "/usr/lib/python2.5/site-packages/django/db/models/manager.py", line 123, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 308, in get_or_create
transaction.savepoint_rollback(sid)
File "/usr/lib/python2.5/site-packages/django/db/transaction.py", line 199, in savepoint_rollback
connection._savepoint_rollback(sid)
File "/usr/lib/python2.5/site-packages/django/db/backends/__init__.py", line 67, in _savepoint_rollback
self.cursor().execute(self.ops.savepoint_rollback_sql(sid))
InternalError: no such savepoint

最佳答案

如果你想测试使用交易的代码,你需要继承TransactionTestCase而不是 TestCase

例如:

from django.test import TransactionTestCase

class MyTests(TransactionTestCase):
...

它可能在 MySql 中传递,因为您使用的是不支持事务的 MyISAM 表

关于python - Django 测试失败,内部错误 : no such savepoint. DB : Postgres, 通过 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1674530/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com