gpt4 book ai didi

django 无法通过 pgbouncer 删除测试数据库

转载 作者:行者123 更新时间:2023-11-29 11:24:51 25 4
gpt4 key购买 nike

我在 Django 中使用 pgbouncer。我已经将 test_foo 数据库添加到它的配置中以便能够运行测试,因为显然 Django 不能为测试数据库使用不同的端口。现在测试运行但最后,当 Django 试图删除测试数据库时,我收到

django.db.utils.DatabaseError: database "test_foo" is being accessed by other users
DETAIL: There are 1 other session(s) using the database.

我想这是由 pgbouncer 存储的打开连接引起的。我能做些什么?

最佳答案

这不是完美的解决方案,但可以解决问题。您可以通过添加到您的 settings.py 来强制 Django 在运行单元测试时使用不同的数据库设置:

if 'test' in sys.argv or 'test_coverage' in sys.argv:    
# Use 5432 as db port (avoid going through pgbouncer, can't delete test DB).
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'xxx',
'USER': 'xxx',
'PASSWORD': 'xxx',
'HOST': '',
'PORT': '5432'
},
}

关于django 无法通过 pgbouncer 删除测试数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8047742/

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