TAGS:

ruby  rails  migration  database  environment 

Related:


Setting Environment For Rails Migration.

You can set the environment for rails migration RAILS_ENV using one of two ways:

First, Using rake command line as:

rake db:migrate RAILS_ENV=test
#or
rake db:migrate RAILS_ENV=development
#or
rake db:migrate RAILS_ENV=production

Second, Using system variables in command line

export RAILS_ENV=test
#or
export RAILS_ENV=development
#or
export RAILS_ENV=production

Or editing ~/.bashrc file to add RAILS_ENV as:

echo 'RAILS_ENV=test' >> ~/.bashrc
#or
echo 'RAILS_ENV=test' >> ~/.bashrc
#or
echo 'RAILS_ENV=test' >> ~/.bashrc

And then, refresh your system variables using:

source ~/.bashrc

You can assure that you have system variable RAILS_ENV and its value using :

echo $RAILS_ENV

Note, The database for that environment must be created before its migration.

Now, Take a look to this tutorial video: