1

当我运行一个新的空 rails (4.0) 站点时出现此错误:

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

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

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

它还创建了一个空数据库,名为“test.db”,如下所示。简单的红宝石脚本:

  require "sqlite3"

  puts "hello world"

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

  puts "test.db is done."

我的结论是sqlite3 gem 工作正常,并且在某个地方的 rails 内部有些问题。欢迎提出建议或解释。

在关于Gemfile的评论之后的一点更新:

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

另外,我使用了bundle show命令,我觉得这很奇怪

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

当我进行捆绑安装时,输出列表不包括 sqlite3。我应该添加 Gemfile,其他所有内容都是由“ rails new train ”命令(项目名称,当然是“ train ”)直接生成的。

环境是在 Windows 7 64 位 PC 上安装 Ruby v2、Rails v4。我有 PIK 来管理不同版本的 ruby​​。欢迎提出建议,在此先感谢,威尔。

一切都是/应该是全新的 Rails 4/Ruby 2 配置。我也在添加服务器的堆栈转储,因为理论上全新安装应该可以工作

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'
4

2 回答 2

1

有两条新闻要报道。我在 PIK 邮件列表上得到了一个解释:

[ 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 version 1.3.5

阅读sparklemotion后错误在于 Bundler。我猜想被理解。

从积极的一面。我使用 Rails 4 和 Ruby 2 来制作 rails 项目,并且可以通过将 Gemfile 更改为使用 jdbc 驱动程序来运行服务器以使用 JRuby 使用 SQLite3,如下所示:

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

看起来 Bundler 似乎有针对 SQLite3 的东西,不是吗?

最后一件事。使用 Ruby v2 构建的 Sqlite3 gem 可以正常工作,如我的玩具测试程序所示。由于它只是一个 Gem ... Bundler 问题可能会针对其他一些 gem 弹出 - 请注意,最好在看到问题后立即升级:

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

只需检查列表

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

工作一种享受!

:-)

于 2013-10-29T20:41:16.107 回答
0

你有没有:

gem 'sqlite3'

或类似的东西

gem 'sqlite3', group: [:development, :test]

在您的 Gemfile 中?

于 2013-10-29T09:03:05.600 回答