在我的rails 3应用程序中,每次运行rake db:test:在我的本地开发环境中准备,我的PostgreSQL数据库被删除,我收到以下消息:
Chriss-MacBook-Pro-2:castingflow Fif$ rake db:test:prepare
rake aborted!
PG::ObjectInUse: ERROR: database "Fif" is being accessed by other users
DETAIL: There are 3 other session(s) using the database.
: DROP DATABASE IF EXISTS "Fif"
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `exec'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in execute'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.15/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/connection_adapters/postgresql_adapter.rb:772:in `drop_database'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/railties/databases.rake:623:in `drop_database'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/railties/databases.rake:532:in `block (3 levels) in <top (required)>'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/railties/databases.rake:559:in `block (3 levels) in <top (required)>'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/bin/ruby_executable_hooks:15:in `eval'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)
我知道有其他会话使用数据库,但为什么数据库因为这个而被删除?当我在开发环境中使用sqlite时,这种情况永远不会发生。我该如何解决这个问题?
答案 0 :(得分:1)
如果有连接用户,PostgreSQL不会让您删除数据库。我不知道,但也许SQLite并不关心。是&#34; Fif&#34;你的测试数据库?还是你的开发数据库?有点奇怪,你将有3个连接到你的测试数据库,除非你有一些自动测试框架,如guard / zeus等。
无论如何,您需要关闭它们,以便重新创建该数据库。