Django测试因InternalError失败:没有这样的保存点。 DB:Postgres,传递mysql

时间:2009-11-04 15:27:01

标签: python mysql django postgresql

有趣的是它也适用于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

1 个答案:

答案 0 :(得分:3)

如果要测试使用事务的代码,则需要子类化TransactionTestCase而不是TestCase

例如:

from django.test import TransactionTestCase

class MyTests(TransactionTestCase):
    ...

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