【发布时间】:2015-06-28 02:38:09
【问题描述】:
我是 Rails 新手,在学习完 Heroku 教程后,我使用 PostgresQL 建立了一个项目。
一位也在学习 Rails 的朋友遵循了一个不同的教程,该教程使用 SQLite 作为数据库,我已经克隆了该教程。
使用 SQLite 项目启动 Rails 服务器时,我不断收到错误消息,提示该项目正在尝试使用 PostgresQL,并告诉我将 gem pg 添加到我的 Gemfile。
我似乎只能在网上找到各种关于从 MySQL/SQLite/etc 迁移到 PostgresQL 的帖子,但我不打算迁移。
我的database.yml如下:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
RubyMine 报错是:
/usr/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/Ty/Rails/TSCLunch/web/bin/rails server -b 0.0.0.0 -p 3000 -e development
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/Ty/.gem/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': 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). (Gem::LoadError)
from /Users/Ty/.gem/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
from /Users/Ty/.gem/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:50:in `establish_connection'
from /Users/Ty/.gem/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:27:in `each'
from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
from /Users/Ty/.gem/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/railtie.rb:116:in `block in <class:Railtie>'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!'
from /Users/Ty/Rails/TSCLunch/web/config/environment.rb:5:in `<top (required)>'
from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /Users/Ty/Rails/TSCLunch/web/config.ru:3:in `block in <main>'
from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `instance_eval'
from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `initialize'
from /Users/Ty/Rails/TSCLunch/web/config.ru:in `new'
from /Users/Ty/Rails/TSCLunch/web/config.ru:in `<main>'
from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `eval'
from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `new_from_string'
from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:40:in `parse_file'
from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:208:in `app'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/server.rb:61:in `app'
from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/server.rb:78:in `start'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/Ty/Rails/TSCLunch/web/bin/rails:4:in `require'
from /Users/Ty/Rails/TSCLunch/web/bin/rails:4:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
Process finished with exit code 1
【问题讨论】:
-
是否有 DATABASE_URL 环境变量? (
echo $DATABASE_URL是否输出任何内容)
标签: ruby-on-rails ruby sqlite postgresql heroku