【发布时间】:2014-11-22 11:32:45
【问题描述】:
我正在运行 Django==1.7 和 psycopg2==2.5.4,但我无法运行任何测试。
当我尝试运行我的任何 django 测试用例(通过运行 ./manage test <app>)时,我收到以下错误:
Creating test database for alias 'default'...
Got an error creating the test database: CREATE DATABASE cannot run inside a transaction block
...
Destroying old test database 'default'...
Got an error recreating the test database: current transaction is aborted, commands ignored until end of transaction block
我的数据库设置非常基础:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydb',
}
}
我使用的用户(系统是 Ubuntu 14.04)拥有完整的 postgres 管理员权限,我可以成功手动创建/删除数据库:
(env)user@host:~$ createdb test_mydb
(env)user@host:~$ dropdb test_mydb
(env)user@host:~$
我的模型迁移似乎很好 - 我可以删除数据库,成功运行迁移并且我的 Web 应用程序功能正常 - 我只是无法运行测试。
我在同一台机器上有另一个 django 1.7 项目,使用相同的基本 postgres 数据库设置,以相同的用户身份运行并且测试运行良好。
有什么想法可以阻止测试运行吗?
【问题讨论】:
-
通过排除过程,我确定这与
djorm-ext-pool应用程序有关。当我从INSTALLED_APPS中删除djorm_pool时,我不再收到错误消息。 -
这适合自我回答,做得很好。它一定是太早建立交易了。
标签: django postgresql psycopg2 django-tests