2015-07-05 45 views
0

我在用mysql數據庫支持的rails上創建一個新的應用程序。但是,當我嘗試運行應用程序,它崩潰,出現以下錯誤信息:Ruby on Rails應用程序支持MySQL數據庫在Heroku上崩潰並顯示錯誤消息

Running `rails console` attached to terminal... up, run.1388 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.3/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 /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec' 
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.3/lib/active_record/connection_handling.rb:50:in `establish_connection' 
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.3/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>' 
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval' 
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook' 
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks' 
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:44:in `each' 
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks' 
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.3/lib/active_record/base.rb:315:in `<module:ActiveRecord>' 
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.3/lib/active_record/base.rb:26:in `<top (required)>' 
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.3/lib/active_record/relation/predicate_builder.rb:121:in `<class:PredicateBuilder>' 
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.3/lib/active_record/relation/predicate_builder.rb:2:in `<module:ActiveRecord>' 
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.3/lib/active_record/relation/predicate_builder.rb:1:in `<top (required)>' 
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require' 
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `block in require' 
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency' 
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require' 
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies/autoload.rb:70:in `block in eager_load!' 
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies/autoload.rb:70:in `each_value' 
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies/autoload.rb:70:in `eager_load!' 
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.3/lib/active_record.rb:159:in `eager_load!' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/application/finisher.rb:56:in `each' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/initializable.rb:30:in `instance_exec' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/initializable.rb:30:in `run' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/initializable.rb:55:in `block in run_initializers' 
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each' 
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component' 
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from' 
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component' 
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each' 
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component' 
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/initializable.rb:54:in `run_initializers' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/application.rb:352:in `initialize!' 
from /app/config/environment.rb:5:in `<top (required)>' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/application.rb:328:in `require' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/application.rb:328:in `require_environment!' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:142:in `require_application_and_environment!' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:67:in `console' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>' 
from /app/bin/rails:8:in `require' 
from /app/bin/rails:8:in `<main>' 

我不明白,錯誤本身的第一道防線。我將應用程序配置爲在MySQL數據庫上運行,但它指定了PostgreSQL。我是一個新手,你能幫我調試我的應用程序。這只是被命令創建一個基本的應用程序:

rails new myFirstApplication 

沒有更改向它提出的。 這裏是一個被配置到MySQL使用我的database.yml文件:

default: &default 
adapter: mysql2 
encoding: utf8 
pool: 5 
username: root 
password: 80517326A! 
socket: /var/run/mysqld/mysqld.sock 

development: 
<<: *default 
database: myFirstApplication_development 

test: 
<<: *default 
database: myFirstApplication_test 


production: 
    <<: *default 
    database: myFirstApplication_production 
    username: myFirstApplication 
    password: <%= ENV['MYFIRSTAPPLICATION_DATABASE_PASSWORD'] %> 
+0

Heroku不適用於mysql,它只適用於postgres。 – BroiSatse

+0

@BroiSatse哦,我明白了!是否有可能在開發環境中使用MySQL,但在生產環境中(即在Heroku中)使用PostgreSQL?如果是這樣,怎麼樣? –

+0

你可以做到這一點,但我不會推薦這一點--MySQL在很多方面的表現與PostgreSQL不同,並且在開發中可能無法在生產中使用。 – BroiSatse

回答

0

只需添加pg寶石的生產環境中您的Gemfile,多數民衆贊成:

group :production do 
    gem 'pg' 
end 

無需改變你database.yml。 Heroku不使用應用程序的database.yml進行數據庫連接。它使用PostgreSQL,您的應用應該擁有pg寶石。 Heroku將即時創建數據庫設置。

相關問題