Ruby-on-rails rails sqlite 适配器错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7371809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 01:56:58  来源:igfitidea点击:

rails sqlite adapter error

ruby-on-railsrubysqlite

提问by Ohad Horesh

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

我正在按照rails 教程中的说明操作,但在尝试使用 scaffold 命令时卡住了。

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 install 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:

我的 Gemfile 看起来像这样:

source 'http://rubygems.org'
gem 'rails', '3.1.0'  
gem 'sqlite3', '1.3.3'  
...

I'm running on Windows 7 x64 OS.

我在 Windows 7 x64 操作系统上运行。

Any ideas?

有任何想法吗?

回答by Ohad Horesh

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:

好的,我发现了问题。我注意到我的 Rails 安装有 SQLite 1.3.3 和 1.3.4 我改变了我的 Gemfile:

gem 'sqlite3', '1.3.3'

to:

到:

gem 'sqlite3', '1.3.4'

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

那解决了问题。感谢@holger-just将我指向他们回答中错误消息中的相关行。

回答by jduyan

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

参考:http: //kenai.com/jira/browse/ACTIVERECORD_JDBC-19

回答by Holger Just

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 execlike so

要解决这个问题,你应该总是bundle exec像这样运行你的命令

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

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

这样,您就可以让捆绑程序完全控制您的工作$LOAD_PATH,这可能会解决这些问题。

回答by thetrystero

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.

我也有这个错误,买我的问题略有不同。问题是 sqlite3-ruby 已被弃用,由 sqlite3 取代。在 michael hartl 的网络广播中,他仍然使用旧的 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!

我编辑了我的 gemfile 以使用 sqlite 1.3.4 而不是 sqlite3-ruby 1.3.1。重新运行捆绑安装,瞧,问题解决了!

回答by mopsled

Instead of

代替

gem install activerecord-sqlite3-adapter

run

gem install sqlite3

回答by Apiwat Hanvongse

Also on Rails Tutorial, ran:

同样在 Rails 教程上,运行:

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

请安装 sqlite3 适配器: gem install activerecord-sqlite3-adapter (sqlite3 不是捆绑包的一部分。将其添加到 Gemfile。)。

Ran:

冉:

$ gem install activerecord-sqlite3-adapter

$ gem install activerecord-sqlite3-adapter

Got:

得到了:

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

错误:在任何存储库中都找不到有效的 gem 'activerecord-sqlite3-adapter' (>= 0)

Changed Gemfile according to one of the answers above:

根据上述答案之一更改了 Gemfile:

gem 'sqlite3', '1.3.4'

宝石'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:

再次尝试运行 $ rake db:migrate ,但又出现了另一个错误,这一次类似于上面的答案:

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

请安装 sqlite3 适配器:(gem install activerecord-sqlite3-adapter无法激活 sqlite3 (~> 1.3.5),已激活 sqlite3-1.3.4。确保所有依赖项都添加到 Gemfile。)

So changed Gemfile to:

所以将 Gemfile 更改为:

gem 'sqlite3', '1.3.5'

宝石'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.

并收到另一条错误消息以确保 'gem install sqlite3 -v '1.3.5' 成功(wtf?!好吧)。安装成功,运行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.

根据上面的另一个建议。它终于奏效了。该教程警告说设置过程很费力,但我觉得我必须至少与其他 5 个人混合搭配。希望这对下一个人有所帮助。