【发布时间】:2011-02-12 08:41:30
【问题描述】:
我在使用 Postgresql 和 Rails 3 进行测试时遇到问题。
开发和生产数据库我都可以正常工作,但是当我运行rake或db:test:prepare等时,测试数据库会抛出以下错误。
PGError: ERROR: source database "template1" 正被其他用户访问
更新
谷歌搜索,在 Postgres 中使用 createdb 创建新数据库时,似乎应该使用 template0 而不是 template1。在典型的“所以我会删除原因。但不是症状”时尚,我找到vendor/rails/railities/lib/task/databases.rake并将第109行更改为:
createdb #{enc_option} \
-U "#{abcs["test"]["username"]}" \
-T template0 #{abcs["test"]["database"]}
但我真的不想这样做,因为我使用 Rails 作为 GEM,有人知道另一种解决方法或修复方法吗?
database.yml:
development:
adapter: postgresql
encoding: unicode
database: test1234_development
pool: 5
username: holden
password: postgres
test:
adapter: postgresql
encoding: unicode
database: test1234_test
pool: 5
username: holden
password: postgres
完全错误:
注意:数据库“test1234_test”不存在,正在跳过
PGError:错误:其他用户正在访问源数据库“template1”
详细信息:还有 1 个其他会话正在使用该数据库。
: 创建数据库 "test1234_test" ENCODING = 'unicode'
【问题讨论】:
标签: ruby-on-rails unit-testing ruby-on-rails-3 testing postgresql