rails sqlite adapter error

前端 未结 6 1800
傲寒
傲寒 2020-12-16 12:21

I\'m following the instructions in rails tutorial and got stuck when trying to use the scaffold command.

When running:

rails generate scaffold User n         


        
相关标签:
6条回答
  • 2020-12-16 12:56

    Also on Rails Tutorial, ran:

      $ rake db:migrate
    

    Got the following error:

    Please install the sqlite3 adapter: gem install activerecord-sqlite3-adapter (sqlite3 is not part of the bundle. Add it to Gemfile.).

    Ran:

    $ gem install activerecord-sqlite3-adapter

    Got:

    ERROR: Could not find a valid gem 'activerecord-sqlite3-adapter' (>= 0) in any repository

    Changed Gemfile according to one of the answers above:

    gem 'sqlite3', '1.3.4'

    Got another error so had to install:

    $ gem install sqlite3 -v '1.3.4'
    

    Tried running $ rake db:migrate again, but got another error, this time resembling the answer above:

    Please install the sqlite3 adapter: gem install activerecord-sqlite3-adapter (can't activate sqlite3 (~> 1.3.5), already activated sqlite3-1.3.4. Make sure all dependencies are added to Gemfile.)

    So changed Gemfile to:

    gem 'sqlite3', '1.3.5'

    And got another error message to make sure 'gem install sqlite3 -v '1.3.5' succeeds (wtf?! alright again). Installed it successfully, ran bundle install.

    Tried running:

    $ rake db:migrate
    

    Nothing happened, so tried:

    $ bundle exec rails generate scaffold User name:string email:string
    

    Per another suggestion above. And it finally worked. The tutorial warned of a laborious setup process, but I felt like I had to mix and match from at least 5 other people. Hope this helps the next person.

    0 讨论(0)
  • 2020-12-16 13:00

    Ok I found the problem. I noticed that my Rails installation has both SQLite 1.3.3 and 1.3.4 I changed my Gemfile from:

    gem 'sqlite3', '1.3.3'
    

    to:

    gem 'sqlite3', '1.3.4'
    

    That solved the problem. Thanks @holger-just for pointing me to the relevant line in the error message in their answer.

    0 讨论(0)
  • 2020-12-16 13:03

    i had this error too, buy my problem was slightly different. the issue is that sqlite3-ruby is deprecated, to be replaced by sqlite3. in michael hartl's webcast, he still used the old sqlite3-ruby.

    I edited my gemfile to use sqlite 1.3.4 instead of sqlite3-ruby 1.3.1. re-ran bundle install, and voila, problem solved!

    0 讨论(0)
  • 2020-12-16 13:07

    Instead of

    gem install activerecord-sqlite3-adapter
    

    run

    gem install sqlite3
    
    0 讨论(0)
  • 2020-12-16 13:10

    suggested install command:

    gem install activerecord-jdbc-sqlite3-adapter
    

    actual install command:

    gem install activerecord-jdbcsqlite3-adapter
    

    Reference: http://kenai.com/jira/browse/ACTIVERECORD_JDBC-19

    0 讨论(0)
  • 2020-12-16 13:14

    The important part of your error message is this snippet:

    can't activate sqlite3 (~> 1.3.4), already activated sqlite3-1.3.3-x86-mingw32. Make sure all dependencies are added to Gemfile.
    

    To fix that, you should always run your commands through bundle exec like so

    bundle exec rails generate scaffold User name:string email:string 
    

    That way, you give bundler to take full control over your $LOAD_PATH which will probably resolve these issues.

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