简体   繁体   English

Heroku在我的Rails应用程序Gemfile中无法识别“ pg”宝石

[英]Heroku won't recognize 'pg' gem in my Rails app Gemfile

I'm still a relative newbie to Ruby on Rails, and I'm a complete newbie with Heroku. 我仍然是Ruby on Rails的相对新手,并且是Heroku的完整新手。

I've set up my Rails app to use postgres instead of sqlite3, both in development and in production, and I've put "gem 'pg'" in my Gemfile. 我已经将Rails应用程序设置为在开发和生产中都使用postgres而不是sqlite3,并且在我的Gemfile中放置了“ gem'pg'”。 And locally, my app is working just fine. 在本地,我的应用程序运行良好。

Making it work on Heroku is a different story. 使它在Heroku上工作是另一回事。 After I've pushed my app to Heroku, when I type in "heroku run rake db:migrate", it tells me, "rake aborted! Specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile." 将应用程序推送到Heroku之后,当我输入“ heroku run rake db:migrate”时,它告诉我“ rake aborted!为数据库适配器指定了'postgresql',但未加载gem 'pg' 。添加gem 'pg'到您的Gemfile。”

Yes, gem 'pg' is in my Gemfile, but I'm still getting this error. 是的,我的Gemfile中有gem'pg gem 'pg' ,但是我仍然遇到此错误。

What gives? 是什么赋予了?

Here's what my Gemfile looks like right now: 这是我的Gemfile现在的样子:

source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails',        '4.0.1'
gem 'pg'

group :assets do
end

gem 'bcrypt-ruby', '~> 3.1.2'
gem 'haml'
gem 'devise', '3.0.0.rc'
gem 'protected_attributes'
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
gem 'knockout-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'unicorn'
  gem 'rails_12factor', '0.0.2'
end

Here's what my database.yml is like: 这是我的database.yml的样子:

development:
  adapter: postgresql
  encoding: unicode
  database: financemeter
  pool: 5
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: financemeter
  pool: 5
  timeout: 5000

production:
  adapter: postgresql
  database: dbe67fgdnnqg88
  pool: 5
  timeout: 5000
  user: njatxlpjjrzfoe
  password: HULxOtPALAk4FnzZe-_737TvPc

And here are the full error logs when I try to migrate on heroku. 这是当我尝试在heroku上迁移时的完整错误日志。 (Again, locally I'm fine. I'm working locally on a MacBook if that matters.) (同样,在本地我很好。如果这很重要,我将在MacBook上本地工作。)

/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/connection_specification.rb:58:in `rescue in resolve_hash_connection'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/connection_specification.rb:55:in `resolve_hash_connection'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/connection_specification.rb:46:in `resolve_string_connection'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/connection_specification.rb:32:in `spec'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_handling.rb:39:in `establish_connection'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/railtie.rb:176:in `block (2 levels) in <class:Railtie>'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:27:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/railtie.rb:174:in `block in <class:Railtie>'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `instance_exec'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `run'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:54:in `run_initializers'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:215:in `initialize!'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
/app/config/environment.rb:5:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `block in require'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:214:in `load_dependency'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:189:in `require_environment!'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:250:in `block in run_tasks_blocks'

Do you have postgresql installed on your machine? 您的机器上安装了postgresql吗?
If not, use homebrew to install pg. 如果没有,请使用自制软件安装pg。
Once installed, make sure you initialize the pg datastore. 安装后,请确保初始化pg数据存储。

also, depending how your pg is installed, you might need to specify the username and host in your database.yml file 另外,根据pg的安装方式,您可能需要在database.yml文件中指定用户名和主机

  username: someuser_on_pg
  host: localhost

Hope that helps 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM