Heroku数据库配置指定不存在的mysql适配器

时间:2013-01-25 07:39:25

标签: ruby-on-rails heroku mysql2

我似乎无法克服heroku上面的错误。我在本地运行带有mysql2 gem的rails 3就好了,但是当移动到heroku时这似乎会破坏。

首先,我使用的是ClearDB。

其次,当我部署并尝试运行heroku run rake db:migrate时,heroku告诉我需要添加mysql gem和activerecord-mysql-adapter。当我使用mysql2时,为什么会发生这种情况?

第三,当我将mysql和适配器添加到我的项目中时,我发现heroku的问题告诉我在项目中需要那些宝石。所以,我再次运行rake db:migrate,现在我得到了不同的错误......

rake aborted!
database configuration specifies nonexistent mysql adapter
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:133:in `establish_connection'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:26:in `block in on_load'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:25:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:25:in `on_load'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/railtie.rb:74:in `block in <class:Railtie>'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `instance_exec'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `run'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:55:in `block in run_initializers'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `run_initializers'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:136:in `initialize!'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `method_missing'
/app/config/environment.rb:5:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `block in require'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:103:in `require_environment!'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'

当我查看我的database.yml时,我看到heroku已经注入了postgresql作为适配器,但错误输出明确表示mysql ...如果有人可以帮我解决这个问题,我会非常感激。我不知道如何处理heroku ...

2 个答案:

答案 0 :(得分:5)

Heroku注入了postgresql,因为你没有指定heroku配置属性DATABASE_URL。

我在这篇文章中提供了详细的说明 - https://stackoverflow.com/a/17815729/1626020

但简而言之,您需要使用以下内容进行设置:

heroku config:set DATABASE_URL=mysql2://bb06ca765fb123:71b6d123@us-cdbr-east-04.cleardb.com/heroku_703eded6aebc123?reconnect=true 

记住你的database.yml被Heroku完全忽略了。那是对的,被忽略了。 DATABASE_URL就是最重要的。

答案 1 :(得分:-1)

Heroku使用Postgresql。

您可以在开发/测试环境中使用mysql2,在生产中使用postgresql(即在Heroku上)。

group :development, :test do
  gem 'mysql2'
end

group :production do
  gem 'pg'
end