Rails 4 - Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded

前端 未结 9 879
一整个雨季
一整个雨季 2020-12-02 06:13

In my gemfile I have:

gem \'mysql2\'

My database.yml is as follows:

default: &default
  adapter: mysql2
  database: <         


        
相关标签:
9条回答
  • 2020-12-02 06:50

    Had same issue but adding source 'https://rubygems.org' to the top of gem file solved issue.

    Steps:

    add source 'https://rubygems.org' to your gem file. Comment out mysql2 gem and add gem 'mysql2', '~> 0.3.18' Run bundle install

    0 讨论(0)
  • Just a further update - the solution in the question is correct.

    The 4th comment is worth taking note of:

    This isn't a bug with mysql2, it's a problem with the requirement in the ActiveRecord adapter: http://github.com/rails/rails/issues/21544. This is fixed in rails master: https://github.com/rails/rails/commit/5da5e3772c32593ecf2f27b8865e81dcbe3af692

    I was able to tie Rails 4.2.4 to the 4-2-stable branch and get it working with the latest mysql2:

    gem 'rails', '~> 4.2.4', git: "git://github.com/rails/rails.git", branch: '4-2-stable'
    gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] #-> Rails 4.1+
    
    #DB
    gem 'mysql2'
    
    0 讨论(0)
  • 2020-12-02 06:56

    As a complete beginner i got confused on how to do this so I just did a trial check and finally got my server working , here is how i got it working .

    get into the file of working directory("work") and from there get into the file of the app you created("sample_app")which has mysql 2 installed go to gem file ("Gemfile")edit gem 'mysql2' to gem 'mysql2', '~> 0.3.18'

    now go back to cmd and run command "bundle install".

    so the directory to edit file taking consideration of above files in brackets should be . "c\work\sample_app\Gemfile"

    hope i was of some help .

    0 讨论(0)
提交回复
热议问题