0

我正在尝试使用 heroku 使用的免费托管。我尝试了很多选项,但仍然在 heroku 日志上收到此错误“请安装 postgresql 适配器:`gem install ...”。

首先,我在大约 1 年前遇到了同样的错误,我期待 heroku 现在能解决这个问题。

我必须做些什么才能让它发挥作用?

这是我的 GEMFILE:

  1 source 'https://rubygems.org'
  2
  3 gem 'rails', '3.2.14'
  4
  5 # Bundle edge Rails instead:
  6 # gem 'rails', :git => 'git://github.com/rails/rails.git'
  7
  8 gem 'activerecord-postgresql-adapter'
  9 gem 'typhoeus'
 10
 11 # Gems used only for assets and not required
 12 # in production environments by default.
 13 group :assets do
 14   gem 'sass-rails',   '~> 3.2.3'
 15   gem 'coffee-rails', '~> 3.2.1'
 16   gem "twitter-bootstrap-rails"
 17   # See https://github.com/sstephenson/execjs#readme for more supported runtimes
 18   # gem 'therubyracer', :platforms => :ruby
 19
 20   gem 'uglifier', '>= 1.0.3'
 21 end
 22
 23 group :development do
 24   gem 'debugger'
 25 end
 26
 27 group :development, :test do
 28   gem 'capybara'
 29   gem 'rspec-rails', '~> 2.0'
 30   gem 'factory_girl'
 31   gem 'mysql2'
 32 end
 33
 34 group :test do
 35   gem 'vcr'
 36 end
 37
 38 group :production do
 39   gem 'pg'
 40 end
 41
 42 gem 'proxylocal'
 43
 44 gem 'devise'
 45 gem 'jquery-rails'
 46 gem 'turbolinks'

和我的 config/database.yml 文件:

  1 # MySQL.  Versions 4.1 and 5.0 are recommended.
  2 #
  3 # Install the MYSQL driver
  4 #   gem install mysql2
  5 #
  6 # Ensure the MySQL gem is defined in your Gemfile
  7 #   gem 'mysql2'
  8 #
  9 # And be sure to use new-style password hashing:
 10 #   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
 11 development:
 12   adapter: postgresql
 13   encoding: utf8
 14   reconnect: false
 15   database: resource-management_development
 16   pool: 5
 17   username: root
 18   password:
 19   socket: /tmp/mysql.sock
 20
 21 # Warning: The database defined as "test" will be erased and
 22 # re-generated from your development database when you run "rake".
 23 # Do not set this db to the same as development or production.
 24 test: &test
 25   adapter: postgresql
 26   encoding: utf8
 27   reconnect: false
 28   database: resource-management_test
 29   pool: 5
 30   username: root
 31   password:
 32   socket: /tmp/mysql.sock
 33
 34 production:
 35   adapter: postgresql
 36   encoding: utf8
 37   reconnect: false
 38   database: resource-management_production
 39   pool: 5
 40   username: root
 41   password:
 42   socket: /tmp/mysql.sock
 43
 44 cucumber:
 45   <<: *test

这是完整的错误:

/app/vendor/bundle/ruby/2.0.0/gems/bundler-1.3.2/lib/bundler/rubygems_integration.rb:214:in `block in replace_gem': Please install the postgresql adapter: `gem install activerecord-postgresql-a
dapter` (pg is not part of the bundle. Add it to Gemfile.) (LoadError)

有人可以解决它,所以我和很多人可以部署在这个被上帝遗弃的平台 heroku 上吗?

PS:你可能会注意到我在开发中有一个“gem 'mysql2'”,那是因为我从这里的另一个解决方案中得到了这个。无论如何,没有它它是行不通的。

4

3 回答 3

1

如果您使用 Heroku,则您的 database.yml 中不需要生产组。要使数据库在生产中工作,您需要运行:

heroku run rake db:migrate

要在本地使用它,请查看以下设置:https ://devcenter.heroku.com/articles/heroku-postgresql#local-setup

如果您使用 mysql,请更改您的测试和开发配置,尽管我建议所有三个环境都使用相同的数据库系统。

于 2013-08-19T17:23:47.903 回答
0

据此:https://devcenter.heroku.com/articles/rails3你必须使用 gem pg。所以也许这就是问题所在。

于 2013-08-19T17:13:15.833 回答
0

我不知道你为什么gem 'activerecord-postgresql-adapter'gemfile. 你试过删除这条线吗?

于 2013-08-19T17:35:42.047 回答