【发布时间】:2014-10-11 01:25:33
【问题描述】:
在database.yml(rails 生成的默认文件)中:
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
运行rake about时,出现这个错误:
Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded.
Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by
ActiveRecord).
如果我添加 pg gem,那么 rake about 会给出以下输出:
About your application's environment
Ruby version 2.1.0-p0 (x86_64-darwin13.0)
RubyGems version 2.2.2
Rack version 1.5
Rails version 4.1.0
JavaScript Runtime Node.js (V8)
Active Record version 4.1.0
Action Pack version 4.1.0
Action View version 4.1.0
Action Mailer version 4.1.0
Active Support version 4.1.0
Middleware Rack::Sendfile, ActionDispatch::Static, Rack::Lock, # <ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007f8043154a30>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag
Environment development
Database adapter postgresql
Database schema version 0
知道为什么会这样吗?我想使用 sqlite3 适配器。
【问题讨论】:
-
可以分享完整的database.yml内容吗?
-
在 database.yml 中,你的适配器仍然指定 sqlite3,将其更改为 postgresql,如下所示
-
我正在尝试使用 sqlite3 作为适配器,而不是 postgres。出于某种原因,Rake 说我正在使用 postgres 适配器。
-
@sysofwan 您是在本地机器上还是在 Heroku、Nitrous 等托管服务提供商上?如果是本地机器并且您不想要 postgresql,请从 Gemfile 中删除
gem pg并运行bundle install。让我知道结果。 -
我发现了问题。显然,Rake wan 正在寻找环境变量 DATABASE_URL(我已将其设置为 postgres),这优先于 database.yml 文件。删除环境变量后,一切正常。谢谢大家!
标签: ruby-on-rails rake