rails sqlite adapter error
I'm following the instructions in rails tutorial and got stuck when trying to use the scaffold command.
When running:
rails generate scaffold User name:string email:string
I get the error:
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `rescue in establish_connection': Please install the sqlite3 adapter: `gem instal开发者_运维百科l activerecord-sqlite3-adapter` (can't activate sqlite3 (~> 1.3.4), already activated sqlite3-1.3.3-x86-mingw32. Make sure all dependencies are added to Gemfile.) (RuntimeError)
Running:
gem install activerecord-sqlite3-adapter
I got the error:
ERROR: Could not find a valid gem 'activerecord-sqlite3-adapter' (>= 0) in any repository
ERROR: Possible alternatives: activerecord-jdbcsqlite3-adapter, activerecord-sqlserver-adapter, activerecord-nulldb-adapter, activerecord-spatialite-adapter, activerecord-simpledb-adapter
My Gemfile looks like this:
source 'http://rubygems.org'
gem 'rails', '3.1.0'
gem 'sqlite3', '1.3.3'
...
I'm running on Windows 7 x64 OS.
Any ideas?
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.
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
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.
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!
Instead of
gem install activerecord-sqlite3-adapter
run
gem install sqlite3
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.
精彩评论