【发布时间】:2016-12-24 06:19:03
【问题描述】:
我在 Mac OS X 上运行 Django 1.9、Postgres 9.5.1
当我运行/manage.py test --settings=myproj.settings.local
我明白了:
Creating test database for alias 'default'...
Creating test database for alias 'userlocation'...
Got an error creating the test database: database "test_myproj" already exists
Type 'yes' if you would like to try deleting the test database 'test_myproj', or 'no' to cancel: yes
Destroying old test database for alias 'userlocation'...
Got an error recreating the test database: database "test_myproj" is being accessed by other users
DETAIL: There is 1 other session using the database.
所以,按照This post,我运行:
SELECT
pg_terminate_backend(pid)
FROM
pg_stat_activity
WHERE
pid <> pg_backend_pid()
AND datname = 'test_myproj'
;
继续到DROP DATABASE test_myproj 并尝试再次运行测试,却得到错误DETAIL: There is 1 other session using the database.
查看进程列表,没有任何内容附加到数据库。我杀死了服务器并重新启动,但运行测试的管理命令仍然给我一个错误,即数据库附加了另一个会话。
这真是令人头疼,我以前从未见过——还有其他人吗?
我的设置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'myproj',
'USER': 'myuser',
'PASSWORD': 'mypass',
'HOST': 'localhost',
'PORT': '',
},
'userlocation': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'og_myproj',
'USER': 'og_myuser',
'PASSWORD': 'mypasswd',
'HOST': 'localhost',
'PORT': '5432',
}
}
【问题讨论】:
-
我没有解决方案,但您的问题似乎是,在测试的情况下,两个数据库都将被命名为
test_myproj- 默认情况下它有效,而不是用户定位,检测到此数据库作为现有的。现有会话是当前运行测试的 django 仍在使用的会话。脚本死后,不再有会话;) -
看看那些docs
-
@dahrens,谢谢。稍微修正了设置文件,就像一个魅力。
标签: python django postgresql postgis