【发布时间】:2015-04-23 05:03:49
【问题描述】:
在运行 Rails 4.2、Ruby 2.2.0 和 Rspec 3.2 时,我在运行 Rspec 时收到此错误:
rake aborted!
PG::ConnectionBad: FATAL: permission denied for database "postgres"
DETAIL: User does not have CONNECT privilege.
-e:1:in `<main>'
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)
/Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:393:in `check_pending!': (ActiveRecord::PendingMigrationError)
Migrations are pending. To resolve this issue, run:
bin/rake db:migrate RAILS_ENV=test
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:406:in `load_schema_if_pending!'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:412:in `block in maintain_test_schema!'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:640:in `suppress_messages'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:417:in `method_missing'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:412:in `maintain_test_schema!'
from /Users/ahanmalhotra/Dropbox/Vocabulist/vocabulist/spec/rails_helper.rb:18:in `<top (required)>'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1181:in `require'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1181:in `block in requires='
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1181:in `each'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1181:in `requires='
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration_options.rb:110:in `block in process_options_into'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration_options.rb:109:in `each'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration_options.rb:109:in `process_options_into'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration_options.rb:22:in `configure'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:96:in `setup'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:85:in `run'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:70:in `run'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/exe/rspec:4:in `<top (required)>'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/gemsets/vocabulist/bin/rspec:23:in `load'
from /Users/ahanmalhotra/.rbenv/versions/2.2.0/gemsets/vocabulist/bin/rspec:23:in `<main>'
我的测试数据库在 Heroku 上,我认为 RSpec 正在尝试删除测试数据库并重新创建它。这在 Heroku 上是不允许的,所以这就是出现 permission denied 错误的原因。如果您配置一个全新的数据库并首次运行 RSpec,则不会出现此错误;第一次发生错误后。关于修复的任何想法?
谢谢!
【问题讨论】:
-
这不是在生产中。这是在我的本地机器和我的 Bamboo 服务器上。它们都指向 Heroku 上的同一个测试数据库。
-
正如您所说,Heroku 不允许您删除数据库,因此这不是托管您的开发数据库的好平台。
标签: ruby-on-rails ruby postgresql heroku rspec