使用Capistrano部署时缺少mysql2 Gem错误

时间:2015-12-03 22:18:46

标签: ruby-on-rails ruby ruby-on-rails-4 capistrano mysql2

版本
Rails - 4.2.0
Capistrano - 3.4.0
Ruby - 2.2.2

我正在尝试使用Capistrano将我的应用程序部署到Production,但不断收到此错误:

[42ad5e96] Command: cd ~/deploy/my-app/releases/20151203212725 && ( RAILS_ENV=production ~/.rvm/bin/rvm default do bundle exec rake assets:precompile )
DEBUG [42ad5e96]        rake aborted!
DEBUG [42ad5e96]        Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:50:in `establish_connection'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:27:in `each'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railtie.rb:116:in `block in <class:Railtie>'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/releases/20151203212725/config/environment.rb:5:in `<top (required)>'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/application.rb:328:in `require_environment!'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/application.rb:443:in `block in run_tasks_blocks'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-rails-2.3.3/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'
DEBUG [42ad5e96]        Gem::LoadError: mysql2 is not part of the bundle. Add it to Gemfile.
DEBUG [42ad5e96]        /home/xxx/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/rubygems_integration.rb:292:in `block in replace_gem'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/mysql2_adapter.rb:3:in `<top (required)>'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/ge
DEBUG [42ad5e96]        ms/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:175:in `spec'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:50:in `establish_connection'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:27:in `each'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railtie.rb:116:in `block in <class:Railtie>'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/releases/20151203212725/config/environment.rb:5:in `<top (required)>'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/application.rb:328:in `require_environment!'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/application.rb:443:in `block in run_tasks_blocks'
DEBUG [42ad5e96]        /home/xxx/deploy/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-rails-2.3.3/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'

这是我的Gemfile:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.3.20'
#gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
gem 'sass', '~> 3.4', '>= 3.4.19'
gem 'bourbon', '~> 4.2', '>= 4.2.6'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
#gem 'coffee-rails', '~> 4.1.0'
# Simple Forms gem
gem 'simple_form'
# Handle File Uploads
gem 'paperclip', '~> 4.3'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# User management gem
gem 'devise'
# User permissions/abilities gem
gem 'cancancan'
# Access HTTP and REST resources
gem 'rest-client'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'pry', '~> 0.10.3'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Passenger as the app server
gem 'passenger'

gem 'faraday'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  gem 'capistrano'
  gem 'capistrano-rvm'
  gem 'capistrano-rails'
  gem 'capistrano-passenger'
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Test-Driven-Development enabler
  gem 'rspec'

  gem 'awesome_print'
end

的database.yml

default: &default
  adapter: mysql2
  encoding: utf-8
  host: 127.0.0.1
  username: username
  password: password
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: dev_deb

# 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:
  <<: *default
  database:

production:
  <<: *default
  database: prod_db

1 个答案:

答案 0 :(得分:1)

gem 'mysql2', '~> 0.3.18'适用于rails版本4.x.x

因此,请将您的mysql2 gem降级为版本'~> 0.3.18'

Gemfile

gem 'mysql2', '~> 0.3.18'

然后做:

bundle install