LoginSignup
0
0

More than 5 years have passed since last update.

rails 4.2.4 + mysql2 0.4.3を使う時のトラブル

Last updated at Posted at 2016-03-02

現象

  • dbを生成しようとすると下記のようなエラーが発生する。
  • database adapterとしてmysql2が指定されているが、gemがロードされてない。
% bin/rake db:setup

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).

... snip ...

原因

  • mysql2 adapter 0.4.3を使うためにはrails 4.2.5以上を使う必要がある。
  • 最初はpostgresqlとrails 4.2.4を使っていてmariadbを試すためにmysql2でadapterを切り替えたがGemfileにてバージョン指定をしていなかったので、最新の0.4.3が設置されるようになりトラブルが発生した。

対応

  • 対応方法には二つがあって一つ目はrails 4.2.4をそのまま維持しながら、mysql2 adapterのバージョンを 0.3.xバージョンに指定する。
  • 二つ目はrailsのバージョンを4.2.5以上に上げる。
  • 私は前者より後者を選んだ。
% vi Gemfile

gem 'rails', '4.2.5'

% bundle update
% bin/rake db:setup

-- enable_extension("plpgsql")
   -> 0.0010s
-- create_table("customers", {:force=>:cascade})
   -> 0.0560s
-- create_table("rewards", {:force=>:cascade})
   -> 0.0268s
-- initialize_schema_migrations_table()
   -> 0.0294s
-- enable_extension("plpgsql")
   -> 0.0008s
-- create_table("customers", {:force=>:cascade})
   -> 0.0074s
-- create_table("rewards", {:force=>:cascade})
   -> 0.0078s
-- initialize_schema_migrations_table()
   -> 0.0152s

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0