# Rake db:migrate and script/console in wrong environment

**URL:** <https://www.ruby-forum.com/t/rake-db-migrate-and-script-console-in-wrong-environment/140600>\
**Category:** Rails\
**Created:** [June 16, 2008, 6:25pm UTC](https://www.ruby-forum.com/t/rake-db-migrate-and-script-console-in-wrong-environment/140600 "2008-06-16T18:25:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregthegerg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a88e57/32.png) [@gregthegerg](https://www.ruby-forum.com/u/gregthegerg)\
**Post date:** [June 16, 2008, 6:25pm UTC](https://www.ruby-forum.com/t/rake-db-migrate-and-script-console-in-wrong-environment/140600/1 "2008-06-16T18:25:04Z")

</div>

Hi,

I have the production version of my rails site hosted on a server. (I  
uncommented the line “ENV[‘RAILS\_ENV’] ||= ‘production’” in the  
environment.rb file). I know it’s running in production mode because I  
can tell that the production database is being used and it’s the  
production log that’s being written to.

But, whenever I try to “rake db:migrate” or “script/console”, it’s the  
development database that gets migrated and the development  
environment that gets loaded into console — unless I specify  
“RAILS\_ENV=production”.

What’s up with that? I’ve never had that happen before. The hosting  
company says it’s nothing in their config (of course), so is there  
something in one of my files that could be doing that?

Thanks,  
Greg

---

<div class="post-metadata">

**Author:** ![gregthegerg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a88e57/32.png) [@gregthegerg](https://www.ruby-forum.com/u/gregthegerg)\
**Post date:** [June 16, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/rake-db-migrate-and-script-console-in-wrong-environment/140600/2 "2008-06-16T18:42:18Z")

</div>

On Jun 16, 2008, at 12:24 PM, Greg B. wrote:

> environment that gets loaded into console — unless I specify  
> “RAILS\_ENV=production”.
> 
> What’s up with that? I’ve never had that happen before. The hosting  
> company says it’s nothing in their config (of course), so is there  
> something in one of my files that could be doing that?
> 
> Thanks,  
> Greg

You could set RAILS\_ENV=production in your login script. What do you  
see when you type:

env

into the shell. Does RAILS\_ENV have a value? (equivalently: echo  
$RAILS\_ENV)

Otherwise, you can say:  
script/console production  
or give the setting with each command as you mentioned.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![gregthegerg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a88e57/32.png) [@gregthegerg](https://www.ruby-forum.com/u/gregthegerg)\
**Post date:** [June 16, 2008, 7:14pm UTC](https://www.ruby-forum.com/t/rake-db-migrate-and-script-console-in-wrong-environment/140600/3 "2008-06-16T19:14:07Z")

</div>

RAILS\_ENV is not listed when I type “env”. I don’t see anything there  
that would force the development environment.

Greg

On Jun 16, 12:41 pm, Rob B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![gregthegerg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a88e57/32.png) [@gregthegerg](https://www.ruby-forum.com/u/gregthegerg)\
**Post date:** [June 16, 2008, 8:06pm UTC](https://www.ruby-forum.com/t/rake-db-migrate-and-script-console-in-wrong-environment/140600/4 "2008-06-16T20:06:50Z")

</div>

On Jun 16, 2008, at 1:13 PM, Greg B. wrote:

> RAILS\_ENV is not listed when I type “env”. I don’t see anything there  
> that would force the development environment.
> 
> Greg

The development environment is the default when it isn’t set otherwise.

Chances are that your startup sets RAILS\_ENV (to production).

-Rob
