# Rake db:migrate behaving different for different environments

**URL:** <https://www.ruby-forum.com/t/rake-db-migrate-behaving-different-for-different-environments/156405>\
**Category:** Rails\
**Created:** [December 26, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/rake-db-migrate-behaving-different-for-different-environments/156405 "2008-12-26T19:30:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gourav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/278dde/32.png) [@gourav](https://www.ruby-forum.com/u/gourav)\
**Post date:** [December 26, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/rake-db-migrate-behaving-different-for-different-environments/156405/1 "2008-12-26T19:30:15Z")

</div>

I am wondering in my application for past few days, why the rake  
db:migrate is behaving differently for different environments. Any  
clue is appreciated

Application name : project  
Database name : project\_my\_own  
Environment name : my\_own

If I use simply:  
rake db:migrate

It works, but say I have a separate environment called “my\_own” and if  
I run:  
rake db:migrate RAILS\_ENV=my\_own

It blows up and gives several line of stack trace:  
C:\project\>rake db:migrate RAILS\_ENV=my\_own --trace  
(in C:/project)  
\*\* Invoke db:migrate (first\_time)  
\*\* Invoke environment (first\_time)  
\*\* Execute environment  
rake aborted!  
Mysql::Error: Table ‘project\_my\_own.contents’ doesn’t exist: SHOW  
FIELDS FROM `contents`  
C:/project/vendor/rails/activerecord/lib/active\_record/  
connection\_adapters/abstract\_adapter.rb:189:in `log' C:/project/vendor/rails/activerecord/lib/active_record/ connection_adapters/mysql_adapter.rb:309:in`execute\_without\_reconnect’  
C:/project/vendor/plugins/manage/initializers/  
mysql\_adapter\_extension.rb:7:in `execute' C:/project/vendor/rails/activerecord/lib/active_record/ connection_adapters/mysql_adapter.rb:440:in`columns’  
C:/project/vendor/rails/activerecord/lib/active\_record/base.rb:1220:in  
`columns' C:/project/vendor/rails/activerecord/lib/active_record/base.rb:1239:in`content\_columns’  
C:/project/vendor/plugins/acts\_as\_versioned/lib/acts\_as\_versioned.rb:  
409:in `create_versioned_table' C:/project/vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb: 261:in`acts\_as\_versioned’  
C:/project/app/models/content.rb:16  
C:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in`require’  
C:/project/vendor/rails/activesupport/lib/active\_support/  
dependencies.rb:148:in `require' C:/project/vendor/rails/activesupport/lib/active_support/ dependencies.rb:507:in`new\_constants\_in’  
C:/project/vendor/rails/activesupport/lib/active\_support/  
dependencies.rb:148:in `require' C:/project/vendor/rails/activesupport/lib/active_support/ dependencies.rb:254:in`require\_or\_load’  
C:/project/vendor/rails/activesupport/lib/active\_support/  
dependencies.rb:413:in `load_missing_constant' C:/project/vendor/rails/activesupport/lib/active_support/ dependencies.rb:77:in`const\_missing’  
C:/project/vendor/rails/activesupport/lib/active\_support/  
dependencies.rb:89:in `const_missing' C:/project/app/models/comment.rb:14 C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in`gem\_original\_require’  
C:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`require' C:/project/vendor/rails/activesupport/lib/active_support/ dependencies.rb:148:in`require’  
C:/project/vendor/rails/activesupport/lib/active\_support/  
dependencies.rb:507:in `new_constants_in' C:/project/vendor/rails/activesupport/lib/active_support/ dependencies.rb:148:in`require’  
C:/project/vendor/rails/activesupport/lib/active\_support/  
dependencies.rb:254:in `require_or_load' C:/project/vendor/rails/activesupport/lib/active_support/ dependencies.rb:213:in`depend\_on’  
C:/project/vendor/rails/activesupport/lib/active\_support/  
dependencies.rb:133:in `require_dependency' C:/project/config/../vendor/rails/railties/lib/initializer.rb:364:in`load\_application\_classes’  
C:/project/config/…/vendor/rails/railties/lib/initializer.rb:363:in  
`each' C:/project/config/../vendor/rails/railties/lib/initializer.rb:363:in`load\_application\_classes’  
C:/project/config/…/vendor/rails/railties/lib/initializer.rb:361:in  
`each' C:/project/config/../vendor/rails/railties/lib/initializer.rb:361:in`load\_application\_classes’  
C:/project/config/…/vendor/rails/railties/lib/initializer.rb:182:in  
`process' C:/project/config/../vendor/rails/railties/lib/initializer.rb:112:in`send’  
C:/project/config/…/vendor/rails/railties/lib/initializer.rb:112:in  
`run' C:/project/config/environment.rb:9 C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in`gem\_original\_require’  
C:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`require' C:/project/vendor/rails/activesupport/lib/active_support/ dependencies.rb:148:in`require’  
C:/project/vendor/rails/activesupport/lib/active\_support/  
dependencies.rb:507:in `new_constants_in' C:/project/vendor/rails/activesupport/lib/active_support/ dependencies.rb:148:in`require’  
C:/project/vendor/rails/railties/lib/tasks/misc.rake:3  
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in`execute’  
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `each' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in`execute’  
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in  
`invoke_with_call_chain' C:/ruby/lib/ruby/1.8/monitor.rb:242:in`synchronize’  
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in  
`invoke_with_call_chain' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:588:in`invoke\_prerequisites’  
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `each' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in`invoke\_prerequisites’  
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:577:in  
`invoke_with_call_chain' C:/ruby/lib/ruby/1.8/monitor.rb:242:in`synchronize’  
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in  
`invoke_with_call_chain' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in`invoke’  
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in  
`invoke_task' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in`top\_level’  
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `each' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in`top\_level’  
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in  
`standard_exception_handling' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in`top\_level’  
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in `run' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in`standard\_exception\_handling’  
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in `run' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/bin/rake:31 C:/ruby/bin/rake:16:in`load’  
C:/ruby/bin/rake:16

---

<div class="post-metadata">

**Author:** ![gourav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/278dde/32.png) [@gourav](https://www.ruby-forum.com/u/gourav)\
**Post date:** [December 26, 2008, 8:51pm UTC](https://www.ruby-forum.com/t/rake-db-migrate-behaving-different-for-different-environments/156405/2 "2008-12-26T20:51:07Z")

</div>

On 26 Dec 2008, at 18:29, Gourav T. wrote:

> rake db:migrate
> 
> It works, but say I have a separate environment called “my\_own” and if  
> I run:  
> rake db:migrate RAILS\_ENV=my\_own

That environment has class\_caching turned on which means all models/  
controllers are preloaded when the framework is loaded. If when the  
model is loaded it tries to inspect its table (as the  
acts\_as\_versioned plugins seems to make it do) and that table doesn’t  
exist yet then bad things will happen.

Fred

---

<div class="post-metadata">

**Author:** ![gourav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/278dde/32.png) [@gourav](https://www.ruby-forum.com/u/gourav)\
**Post date:** [December 26, 2008, 8:53pm UTC](https://www.ruby-forum.com/t/rake-db-migrate-behaving-different-for-different-environments/156405/3 "2008-12-26T20:53:28Z")

</div>

Hey Gourav,

Are you using the Content model or the Comment model in either config/  
environment.rb or config/environments/my\_own.rb?

-Ryan

---

<div class="post-metadata">

**Author:** ![gourav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/278dde/32.png) [@gourav](https://www.ruby-forum.com/u/gourav)\
**Post date:** [December 26, 2008, 10:08pm UTC](https://www.ruby-forum.com/t/rake-db-migrate-behaving-different-for-different-environments/156405/4 "2008-12-26T22:08:00Z")

</div>

Hi Fred

Awesome! you are right, class\_caching was turned on. I turned it off  
and it worked!  
But, I would like to pre-load the the models and controllers when the  
framework is loaded, so is there any other option to have caching  
enabled and I can make it work?  
On Dec 26, 2:50 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![gourav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/278dde/32.png) [@gourav](https://www.ruby-forum.com/u/gourav)\
**Post date:** [December 26, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/rake-db-migrate-behaving-different-for-different-environments/156405/5 "2008-12-26T22:10:57Z")

</div>

Hey Ryan,  
I am not using Content and Comment model in any of these files (config/  
environment.rb, config/environments/my\_own.rb)

-Gourav

---

<div class="post-metadata">

**Author:** ![gourav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/278dde/32.png) [@gourav](https://www.ruby-forum.com/u/gourav)\
**Post date:** [December 26, 2008, 10:59pm UTC](https://www.ruby-forum.com/t/rake-db-migrate-behaving-different-for-different-environments/156405/6 "2008-12-26T22:59:01Z")

</div>

On 26 Dec 2008, at 21:07, Gourav T. wrote:

> Hi Fred
> 
> Awesome! you are right, class\_caching was turned on. I turned it off  
> and it worked!  
> But, I would like to pre-load the the models and controllers when the  
> framework is loaded, so is there any other option to have caching  
> enabled and I can make it work?

There’s not a really good solution to this. One way is to have a  
special environment just for running migrations (that obviously uses  
the same database as normal) that has cache classes set to false.

Fred

---

<div class="post-metadata">

**Author:** ![gourav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/278dde/32.png) [@gourav](https://www.ruby-forum.com/u/gourav)\
**Post date:** [December 27, 2008, 12:43am UTC](https://www.ruby-forum.com/t/rake-db-migrate-behaving-different-for-different-environments/156405/7 "2008-12-27T00:43:18Z")

</div>

Many thanks Fred 🙂

I think this solution works fine for now.

On Dec 26, 4:57 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
