Rails 4在sqlite3上失败 [英] Rails 4 fails on sqlite3

查看:116
本文介绍了Rails 4在sqlite3上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 为数据库适配器指定'sqlite3' ,但该宝石没有加载。将`gem'sqlite3``添加到您的Gemfile中。 

我有一个用devkit构建的有效sqlite3 gem。我做了一个愚蠢的测试:

  w:...> ruby hello.rb 
hello world
test.db完成了。

这也创建了一个空数据库,名为test.db,如下所示。简单的ruby脚本:

  requiresqlite3

putshello world

#打开数据库
db = SQLite3 :: Database.newtest.db

putstest.db已完成。

我的结论是, sqlite3 gem工作正常,在轨道内的某些地方出现错误。欢迎您提出建议或解释。



关于 Gemfile 的评论的更新内容:

 #使用sqlite3作为Active Record的数据库
gem'sqlite3',group:[:development,:test]

另外,我使用 bundle show 命令,并且发现这个很奇怪

  w:...> bundle show sqlite3 
找不到gem'sqlite3'。
你的意思是sqlite3吗?

执行捆绑安装时,输出列表不包括 sqlite3的即可。我应该添加Gemfile,其他所有内容都是通过 rails new train 命令(当然,项目名称为' train ')开箱即可生成的。 p>

环境是在Windows 7 64位个人电脑上安装Ruby v2,Rails v4。我有PIK来管理不同版本的红宝石。建议欢迎,预先感谢Will。



一切都应该是新鲜出炉的Rails 4 / Ruby 2配置。我还添加了服务器的堆栈转储,因为从理论上讲,全新安装应该正常工作。

  Gem :: LoadError(为数据库适配器指定'sqlite3',但没有加载gem。将gem'sqlite3'添加到您的Gemfile中。):
activerecord(4.0.0)lib / active_record / connection_adapters / $ _ $ activerecord(4.0.0)lib / active_record / connection_adapters / connection_specification.rb:55:'resolve_hash_connection'
activerecord(4.0.0)lib / active_record / connection_specification.rb: $ _ $ activerecord(4.0.0)lib / active_record / connection_adapters / connection_specification.rb:30:在`spec'中
activerecord(4.0.0)active_record / connection_adapters / connection_specification.rb:46:`resolve_string_connection' lib / active_record / connection_handling.rb:39:在`establish_connection'中
activerecord(4.0.0)lib / active_record / railtie.rb:175:在< class:Railtie>'$中的block(2 levels) b $ b有效支持(4.0.0)lib / active_support / lazy_load_hooks.rb:38:in`instance_eval'
activesupport(4.0.0)lib / active_support / lazy_load_hooks.rb:38:在`execute_hook'
activesupport(4.0 .0)lib / active_support / lazy_load_hooks.rb:45:在`block in run_load_hooks'
activesupport(4.0.0)lib / active_support / lazy_load_hooks.rb:44:在`each'
activesupport(4.0 .0)lib / active_support / lazy_load_hooks.rb:44:在`run_load_hooks'
activerecord(4.0.0)lib / active_record / base.rb:322:在< module:ActiveRecord>'
activerecord(4.0.0)lib / active_record / base.rb:22:在< top(required)>'
activerecord(4.0.0)lib / active_record / query_cache.rb:50:in`restore_query_cache_settings '
activerecord(4.0.0)lib / active_record / query_cache.rb:43:在'rescue in call'中
activerecord(4.0.0)lib / active_record / query_cache.rb:32: '
activerecord(4.0.0)lib / active_record / connection_adapters / abstract / connection_pool.rb:626:in`call'
active记录(4.0.0)lib / active_record / migration.rb:369:在`call'中
actionpack(4.0.0)lib / action_dispatch / middleware / callbacks.rb:29:在`block in call'中
activesupport(4.0.0)lib / active_support / callbacks.rb:373:在`_run__398267657__call__callbacks'
activesupport(4.0.0)lib / active_support / callbacks.rb:80:在`run_callbacks'
actionpack / middleware / callbacks.rb:在`call'中$ 27 $ b actionpack(4.0.0)lib / action_dispatch / middleware / reloader.rb:64:在'call'中
actionpack(4.0.0)lib / action_dispatch / middleware / debug_exceptions.rb:17:在`call'中,
actionpack(4.0.0)lib / action_dispatch / middleware / show_exceptions.rb:30:`call'
railties(4.0.0)lib / rails / rack / logger.rb:38: call_app'
railties(4.0.0)lib / rails / rack / logger.rb:21:在`block in call'中
activesupport(4.0.0)lib / active_support / tagged_logging.rb:67:在`blo ck in tagged'
activesupport(4.0.0)lib / active_support / tagged_logging.rb:25:在`tagged'
activesupport(4.0.0)lib / active_support / tagged_logging.rb:67:
railties(4.0.0)lib / rails / rack / logger.rb:21:在`call'
actionpack(4.0.0)lib / action_dispatch / middleware / request_id.rb:21:在'call'中
rack(1.5.2)lib / rack / methodoverride.rb:21:在`call'中
rack(1.5.2)lib / rack / runtime.rb:17:调用'
activesupport(4.0.0)lib / active_support / cache / strategy / local_cache.rb:83'in'call'
rack(1.5.2)lib / rack / lock.rb:17: in`call'
actionpack(4.0.0)lib / action_dispatch / middleware / static.rb:64:`call'
railties(4.0.0)lib / rails / engine.rb:511:在'call'中
railties(4.0.0)lib / rails / application.rb:97:在`call'中
rack(1.5.2)lib / rack / lock.rb:17:调用'
rack(1.5.2)lib / rack / content_length.rb:14:'call'
rack(1.5.2)lib / rack / handler / webrick.rb:60:服务'
B:/ lang / ruby​​ / v02.00 / lib / ruby​​ / 2.0.0 / webrick / httpserver.rb:138:在'service'中
B:/lang/ruby/v02.00/lib/ruby/2.0.0/webrick/httpserver .rb:94:'run'
B:/lang/ruby/v02.00/lib/ruby/2.0.0/webrick/server.rb:295:在`block in start_thread'


解决方案

我在PIK邮件列表上通过了一个解释:


$ b


[ Luis Lavena ]你没有注明你使用的是哪个版本的Ruby 2.0(ruby - v),但我会假设是x64位,正确吗?

如果是这样,那么您会受到Bundler中的一个错误的影响。这里也有报道:






是的,Ruby v2 64位版本发生问题

  w:... > ruby -v 
ruby​​ 2.0.0p195(2013-05-14)[x64-mingw32]

w:...> bundle -v
Bundler版本1.3.5

阅读 sparklemotion 发布错误在于Bundler。我猜是值得的。



好的一面。我使用Rails 4和Ruby 2来创建rails项目,并且可以通过将Gemfile更改为使用jdbc驱动程序来使用JRuby来运行服务器,如图所示:

 #使用sqlite3作为Active Record的数据库
group:development,:test do
#gem'sqlite3'
gem'activerecord -jdbc-adapter'
gem'jdbc-sqlite3'
end

反对SQLite3的事情不是吗?



最后一件事。我的玩具测试程序演示了Sqlite3 gem可以与Ruby v2一起构建。因为它只是一个宝石... Bundler问题可能会弹出一些其他宝石 - 要警惕,一旦发现问题,最好立即升级:

  w:...> ruby -S gem update bundler --prerelease 
更新已安装的gems
更新打包程序
获取:bundler-1.4.0.rc.1.gem(100%)
成功安装打包程序-1.4.0.rc.1
解析bundler-1.4.0.rc.1的文档
为bundler-1.4.0.rc.1安装ri文档
安装bundler的darkfish文档-1.4.0.rc.1
9秒后完成bundler的安装文档
Gems更新:bundler

只需查看列表

  w:...>捆绑列表
捆绑包含的宝石:

* sprockets(2.10.0)
* sprocket-rails(2.0.1)
* sqlite3(1.3。 8)
* thor(0.18.1)



: - )

I get this error when I run a new empty rails (4.0) site:

Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile.

I have a valid sqlite3 gem built with the devkit. I made a dumb test for that:

w:...> ruby   hello.rb
hello world
test.db is done.

Which also creates an empty database, called "test.db" as shown below. Simple ruby script:

  require "sqlite3"

  puts "hello world"

  # Open a database
  db = SQLite3::Database.new "test.db"

  puts "test.db is done."

My conclusion is that the sqlite3 gem is working OK and that there's something amiss inside rails some place. Suggestions or explanations welcome.

Bit of an update following the comment about Gemfile:

# Use sqlite3 as the database for Active Record
gem 'sqlite3', group: [:development, :test]

In addition, I used the bundle show command, and I find this strange:

w:...> bundle show sqlite3
Could not find gem 'sqlite3'.
Did you mean sqlite3?

When I do a bundle install the output list does not include sqlite3. I should add the Gemfile and everything else was generated right out of the box by a "rails new train" command (project name, 'train' of course).

Environment is an install of Ruby v2, Rails v4 on Windows 7 64-bit PC. I have PIK to manage different versions of ruby. Suggestions welcome, thanks in advance, Will.

Everything is/should be fresh-out-of-the-box Rails 4/Ruby 2 configuration. I'm adding the server's stack dump also, since in theory a fresh install should be working.

Gem::LoadError (Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile.):
  activerecord (4.0.0) lib/active_record/connection_adapters/connection_specification.rb:58:in `rescue in resolve_hash_connection'
  activerecord (4.0.0) lib/active_record/connection_adapters/connection_specification.rb:55:in `resolve_hash_connection'
  activerecord (4.0.0) lib/active_record/connection_adapters/connection_specification.rb:46:in `resolve_string_connection'
  activerecord (4.0.0) lib/active_record/connection_adapters/connection_specification.rb:30:in `spec'
  activerecord (4.0.0) lib/active_record/connection_handling.rb:39:in `establish_connection'
  activerecord (4.0.0) lib/active_record/railtie.rb:175:in `block (2 levels) in <class:Railtie>'
  activesupport (4.0.0) lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
  activesupport (4.0.0) lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
  activesupport (4.0.0) lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
  activesupport (4.0.0) lib/active_support/lazy_load_hooks.rb:44:in `each'
  activesupport (4.0.0) lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
  activerecord (4.0.0) lib/active_record/base.rb:322:in `<module:ActiveRecord>'
  activerecord (4.0.0) lib/active_record/base.rb:22:in `<top (required)>'
  activerecord (4.0.0) lib/active_record/query_cache.rb:50:in `restore_query_cache_settings'
  activerecord (4.0.0) lib/active_record/query_cache.rb:43:in `rescue in call'
  activerecord (4.0.0) lib/active_record/query_cache.rb:32:in `call'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
  activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__398267657__call__callbacks'
  activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
  railties (4.0.0) lib/rails/engine.rb:511:in `call'
  railties (4.0.0) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  B:/lang/ruby/v02.00/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  B:/lang/ruby/v02.00/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  B:/lang/ruby/v02.00/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

解决方案

Two bits of news to report. I was passed an explanation for this on the PIK mailing list:

[Luis Lavena] You don't indicate which version of Ruby 2.0 are you using (the exact output of "ruby -v"), but I will assume is x64 bit, correct?

If that is the case, then you're affected by a bug in Bundler. The same was reported here:

Yes, the problem is happening with Ruby v2 64-bit

 w:...> ruby -v
 ruby 2.0.0p195 (2013-05-14) [x64-mingw32]

 w:...> bundle -v
 Bundler version 1.3.5

Reading the sparklemotion post the error lies with Bundler. To be fathomed I guess.

On the plus side. I used Rails 4 with Ruby 2 to make the rails project and can run the server to use SQLite3 using JRuby by changing the Gemfile to use the jdbc driver, as shown:

# Use sqlite3 as the database for Active Record
group :development, :test do
  #  gem 'sqlite3'
  gem 'activerecord-jdbc-adapter'
  gem 'jdbc-sqlite3'
end

It almost looks like Bundler has a thing against SQLite3 doesn't it?

One last thing. The Sqlite3 gem build OK with Ruby v2 and works, as demonstrated with my toy test program. Since it is just a Gem ... the Bundler problem may pop-up for some other gems -- Be alert, probably best to upgrade as soon as you see the problem:

w:...> ruby -S gem update bundler --prerelease
Updating installed gems
Updating bundler
Fetching: bundler-1.4.0.rc.1.gem (100%)
Successfully installed bundler-1.4.0.rc.1
Parsing documentation for bundler-1.4.0.rc.1
Installing ri documentation for bundler-1.4.0.rc.1
Installing darkfish documentation for bundler-1.4.0.rc.1
Done installing documentation for bundler after 9 seconds
Gems updated: bundler

Just check the list

w:...> bundle list
Gems included by the bundle:
    :
  * sprockets (2.10.0)
  * sprockets-rails (2.0.1)
  * sqlite3 (1.3.8)
  * thor (0.18.1)
    :

Works a treat!

:-)

这篇关于Rails 4在sqlite3上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆