关于数据库适配器与 database.yml 不一致的问题 [英] rake about database adapter inconsistent with database.yml
本文介绍了关于数据库适配器与 database.yml 不一致的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 database.yml
(rails 生成的默认文件)中:
In database.yml
(rails-generated default file):
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
时,出现此错误:
When running rake about
, I have this error:
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
会给出以下输出:
If I add the pg
gem, then rake about
gives this output:
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 适配器.
Any idea why this is happening? I want to use the sqlite3 adapter.
推荐答案
我发现了问题.显然,Rake 正在寻找一个环境变量 DATABASE_URL(我已将其设置为 postgres),这优先于 database.yml 文件.删除环境变量后,一切正常.
I found the problem. Apparently Rake was looking for an environment variable DATABASE_URL (which I had set to postgres) and this takes precedence over the database.yml file. Once I deleted the environment variable, everything works fine.
这篇关于关于数据库适配器与 database.yml 不一致的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文