How does rake decide which database to modify?

Hi All,

I created an 001-xxx initial migration and updated it with results of a
schema::dump, removing the :force => true.

Then I ran rake migrate and (as documented) rake added a schema_info
with version=0.

I’ve got three databases defined in database.yml using scripting I found
Rails Recipes #17.

I defined columns only for the development database.

Happily, rake went to the development database both to dump the schema
add the schema_info table.

Question: How did rake decide to use that database rather than test or

Is it because development is specified first in the yml file?

Is it because development is the only one with tables?

Is it because there’s a setting somewhere that defaults to development
can be modified to target other databases?

I’m running WinXP-Pro/SP2, Ruby 1.8.2-15, Rails 1.1.4, MySQL 5.0.15-nt,
SciTE 1.59, FireFox, Java JDK 1.5.0_06

Thanks in Advance,



On Tue, Oct 24, 2006 at 02:20:13AM -0400, Richard L. wrote:

Hi All,
can be modified to target other databases?
Rails defaults to the development environment (and therefore the
development database). You can switch to production by setting the
RAILS_ENV environment variable to ‘production’. The test evironment is
used automatically for running testcases.

You can, however, specify additional database connections in
database.yml, and explicitly tell activerecord to use these:

class FromOtherDb < ActiveRecord::Base
establish_connection configurations[‘otherdb’]


Jens Krämer
[email protected]

Morning (i still haven’t had that cup of coffee)

I believe you set this using the RAILSENV=production parameter for rake,
and that the default is development. I cannot find reference to this
specifically at the moment - if anyone can point me to a link
documenting the use of RAILSENV I will really appreciate it.

The command that I have used is:

rake db:migrate RAILSENV=production when migrating to production


Hi Ivor and Jens,

Thanks for your responses. It’s 2:43am my time so I’m going to crash
for the night. I’ll try all your approaches tomorrow.

Best wishes,

Hi Jens and Ivor,

Ivor, I used your RAILS_ENV=test clause (not the underscore!) and it
created my (empty) test database.


I saved your input. I’m not ready for a more sophisticated approach at
this time.

Thank you both very much for your responses. I couldn’t find any
documention for this issue through Google searches.

Best wishes,

Hi Ivor and Jens,

I saw your replies a month ago, for which I thank both of you. I just
noticed today that I failed to acknowledge your response. Please accept
this belated apology for that oversight.

Best wishes,