我无法将pg添加到gem文件中。
我做了什么: 改变gem 'sqlite3'
到
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
我尝试在heroku上部署这个rails应用程序 我也做了:
gem install bundler
bundle install --without production
git add .
git commit -m"blahblah"
git push heroku master
然而,在我跑完之后:
heroku run rails db:migrate
这是我得到的错误:
Caused by:
Gem::LoadError: pg is not part of the bundle. Add it to your Gemfile.
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/rubygems_integration.rb:377:in `block (2 levels) in replace_gem'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:2:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/connection_specification.rb:186:in `spec'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:880:in `establish_connection'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_handling.rb:58:in `establish_connection'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/railtie.rb:124:in `block (2 levels) in <class:Railtie>'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:69:in `instance_eval'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:49:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/base.rb:326:in `<module:ActiveRecord>'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/base.rb:25:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/mysql_database_tasks.rb:6:in `<class:MySQLDatabaseTasks>'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/mysql_database_tasks.rb:3:in `<module:Tasks>'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/mysql_database_tasks.rb:2:in `<module:ActiveRecord>'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/mysql_database_tasks.rb:1:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:74:in `<module:DatabaseTasks>'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:35:in `<module:Tasks>'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:2:in `<module:ActiveRecord>'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:1:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/railtie.rb:34:in `block (3 levels) in <class:Railtie>'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:21:in `block in perform'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/command.rb:46:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
/app/bin/rails:4:in `require'
/app/bin/rails:4:in `<main>'
Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)
这是我的宝石文件:
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.4'
# Use sqlite3 as the database for Active Record
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
答案 0 :(得分:1)
删除后可以使用:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
然后简单地添加:
gem 'pg'
到我的宝石文件。 终于跑了:
gem install bundler
git add .
git commit -m"blahblah"
git push heroku master
感谢Mikhail Katrin