ruby-on-rails - Heroku 没有看到 gem 'pg'

标签 ruby-on-rails heroku dbmigrate

需要帮助。

当我尝试制作时 user@X220:~/rails_projects/sample_app$ heroku run rake db:migrate

有一个错误:

Running rake db:migrate on limitless-fjord-69900.... up, run.2816 rake aborted!
Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded.
Add gem 'pg' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:177:in rescue in spec' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:174:inspec' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:50:in establish_connection' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:120:inblock (2 levels) in ' /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:38:in instance_eval' /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:38:inexecute_hook' /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:45:in block in run_load_hooks' /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:44:ineach' /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:44:in run_load_hooks' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/base.rb:315:in' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/base.rb:26:in <top (required)>' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/tasks/mysql_database_tasks.rb:8:in' . . .
Tasks: TOP => db:migrate => db:load_config (See full trace by running task with --trace)

我的 Gemfile 是:

'source 'https://rubygems.org'  
ruby '2.2.0'  
gem 'activerecord', '~> 4.2', '>= 4.2.6'  
gem 'rails', '4.2.6'  
group :development, :test do  
    gem 'byebug'  
  gem 'sqlite3', '~> 1.3', '>= 1.3.11'  
  gem 'rspec-rails', '~> 2.8'  
end  
group :test do  
  gem 'selenium-webdriver', '2.35.1'  
  gem 'capybara', '2.1.0'  
end  
gem 'sass-rails', '~> 5.0'  
gem 'uglifier', '>= 1.3.0'  
gem 'coffee-rails', '~> 4.1.0'  
gem 'therubyracer', platforms: :ruby  
gem 'jquery-rails'  
gem 'turbolinks'  
gem 'jbuilder', '~> 2.0'  
group :doc do  
  gem 'sdoc', '~> 0.4.0', require: false   
end   
gem 'unicorn'  
group :development do  
  gem 'web-console', '~> 2.0'  
  gem 'spring'  
end  
group :production do  
  gem 'rails_12factor'  
  gem 'pg'  
end

出了什么问题?

最佳答案

Gemfile 中删除或注释 gem 'sqlite3',即使它位于 development 组中。 我不知道为什么,但是当您的应用程序包含生产之外的 sqlite gem 时,Heroku 不会运行您的应用程序。

如果您在开发中使用 SQLite,则每次部署到 Heroku 时都必须注释 gem 'sqlite' 并在部署后取消注释。
更好的方法是在开发中使用 Postgres。

关于ruby-on-rails - Heroku 没有看到 gem 'pg',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36153594/

相关文章:

javascript - "HTML tidy"有 JavaScript 或 Ruby 版本吗?

ruby-on-rails - 更新多对多关联中的映射表属性

node.js - Express 4 应用程序 - Node ./bin/www X nodejs ./bin/www

ruby-on-rails - rake 数据库 :migrate is creating tables from other rails projects

ruby-on-rails - Rails - 参数数量错误(:force => true?)

ruby-on-rails - 我可以在测试期间禁用一些 BackgroundRb worker 吗?

git - Heroku local 没有使用我的最新代码。为什么?

heroku - 无法将 ruby​​ on Rails 应用程序推送到 Heroku - 网络问题?

react-native - 如何将数据从React Native AsyncStorage迁移到Flutter?

postgresql - heroku rake 数据库 :migrate failing - how to diagnose/fix?