0

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

首先,我使用的是 ClearDB。

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

第三,当我将 mysql 和适配器添加到我的项目中时,我解决了 heroku 告诉我我的项目中需要这些 gems 的问题。所以,我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...

4

2 回答 2

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 

请记住,Heroku 完全忽略了您的 database.yml。没错,无视。DATABASE_URL 是最重要的。

于 2013-07-23T16:34:09.043 回答
0

Heroku 使用 Postgresql。

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

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

group :production do
  gem 'pg'
end
于 2013-01-25T10:31:31.957 回答