views:

69

answers:

2

I setup a remote connection locally and need to push it to heroku. When I pushed it to heroku I got an error saying:

RemoteDBName is not configured.

I'm just assuming (also searched and saw) heroku uses their own config.yml file.

A: 

Figured this out, for anybody connecting to a remote database on heroku that might see this:

Heroku replaces your database.yml file with their own, overwriting anything in yours.

To get around this:

  • Create a new file in your config folder, name it whatever.yml
  • Setup the connection string in this file.
  • Create a new file in your initializers folder, I called mine load_remote.rb. In this file write this line of code:

    REMOTE_DB = YAML.load_file("#{RAILS_ROOT}/config/YOURNEWFILEHERE.yml")

  • Establish your connection in any of the remote models with this line of code:

    establish_connection Remote_DB['Whatever you named your connection string in the yml file here']

Ryan
A: 

Let me show you how database configuration is done when you work with Heroku. I think this might be a bit vague in the documentation, some people get confused over it. Lets utilize the console:

zero:~/Projects/crantastic $ heroku console
Ruby console for crantastic.heroku.com
>> puts File.read(Rails.configuration.database_configuration_file)
---
production:
  encoding: unicode
  adapter: postgresql
  username: something_random
  port: 5432
  host: somewhere.at.heroku
  database: something_random
  password: something_random

=> nil
>>

Heroku in practice replaces your apps database.yml when you push your site to their servers. Your data will be stored in one of their fancy PostgreSQL servers no matter what you use locally - this means that you don't have to think about database.yml at all (except for development purpses, naturally). Taps makes sure that everything's db agnostic. If you want to push your latest development db to Heroku, simply run heroku db:push

Colins