Hartl的第7章推送到heroku时,“pg不是捆绑的一部分”,但确实如此

时间:2012-09-08 18:06:47

标签: ruby-on-rails ruby-on-rails-3 heroku rubygems

所以我正在阅读关于RoR的Hartl教程,我在end of chapter 7。我正在尝试部署到heroku。一直到

heroku run rake db:migrate

步骤有效,但该步骤给出了以下错误。我跑了bundle install几次,我不确定我的问题在哪里。此外,即使我运行heroku create --stack cedar然后git push heroku,我也无法在线访问我的heroku应用。当我转到我的heroku应用程序URL时,它只是给我一个应用程序错误。

我目前正在运行Postgres.app并且未部署我的rails服务器。

包括我的Gemfiledatabase.yml。请随意查看http://github.com/sambaek

处的代码

有人可以帮忙吗?谢谢!

终端输出

heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.1
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
Connecting to database specified by DATABASE_URL
rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)

Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)

的Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.8'
gem 'bootstrap-sass', '2.0.4'
gem 'bcrypt-ruby', '3.0.1'

group :development, :test do
  gem 'rspec-rails', '2.11.0'
  gem 'guard-rspec', '0.5.5'
  gem 'pg'
  # gem 'sqlite3'
  gem 'guard-spork', '0.3.2'
  gem 'spork', '0.9.0'
  gem 'factory_girl_rails', '1.4.0'
end

gem 'annotate', '2.5.0', group: :development

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.5'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.2'

group :test do
  gem 'capybara', '1.1.2'
  gem 'rb-fsevent', '0.9.1', :require => false
  gem 'growl', '1.0.3'
end

配置/ database.yml的

# postgresql
development:
  host: localhost
  adapter: postgresql
  encoding: utf8
  database: sample_app_development
  pool: 5
  username: 
  password: 

test:
  host: localhost
  adapter: postgresql
  encoding: utf8
  database: sample_app_test
  pool: 5
  username: 
  password: 

production:
  adapter: postgresql
  encoding: utf8
  database: sample_app_production
  pool: 5
  username:
  password:


# sqlite3
# development:
#   adapter: sqlite3
#   database: db/development.sqlite3
#   pool: 5
#   timeout: 5000

# # Warning: The database defined as "test" will be erased and
# # re-generated from your development database when you run "rake".
# # Do not set this db to the same as development or production.
# test:
#   adapter: sqlite3
#   database: db/test.sqlite3
#   pool: 5
#   timeout: 5000

# production:
#   adapter: sqlite3
#   database: db/production.sqlite3
#   pool: 5
#   timeout: 5000

2 个答案:

答案 0 :(得分:2)

两个问题:

  1. 您在github上的代码显示pg gem位于production组中 - 只需将其从该组中删除,以便它将包含在所有环境中。
  2. 您的问题的更新(显示您的Gemfileconfig/database.yml)会将pg gem置于testdevelopment环境中,赢得奖励由Heroku安装
  3. 我在下面看到了您的答案,但如果您在所有环境中使用Postgres,则不需要将pg gem放在任何组中,因为您似乎是,基于您的config/database.yml文件。

答案 1 :(得分:1)

事实证明,当我运行heroku run rake db:migrate时,它没有安装pg gem,因为我的production中没有单独的Gemfile组。它现在有效。感谢任何花时间尝试解决问题的人!