0

I can't seem to overcome the above error on heroku. I am running rails 3 with the mysql2 gem locally just fine, but this seems to break when moving to heroku.

First, I am using ClearDB.

Second, when I deploy and try to run heroku run rake db:migrate, heroku tells me I need to add the mysql gem and the activerecord-mysql-adapter. Why on earth would this happen when I am using mysql2?

Third, when I add mysql and the adapter to my project, and I get past the issue of heroku telling me I need those gems in my project. So, I run rake db:migrate again, and, now I get different error...

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'

When I check out my database.yml, I see that heroku has injected postgresql as the adapter, however the error outputed clearly states mysql... If anybody can help me on this issue I would really appreciate it. I don't know what to do with heroku...

Sébastien Le Callonnec
  • 26,254
  • 8
  • 67
  • 80
Shawn Deprey
  • 467
  • 8
  • 27

2 Answers2

5

Heroku injected postgresql because you failed to specify the heroku config property DATABASE_URL.

I give detailed instructions in this post - https://stackoverflow.com/a/17815729/1626020

But in a nutshell you need to set it using something like this:

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

Remember your database.yml is completely ignored by Heroku. That's right, ignored. The DATABASE_URL is all that matters.

Community
  • 1
  • 1
Aaron Henderson
  • 1,840
  • 21
  • 20
0

Heroku uses Postgresql.

You could use mysql2 in your dev/test environments and postgresql in production (i.e. on Heroku).

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

group :production do
  gem 'pg'
end
Kieren Hughes
  • 574
  • 3
  • 8