Rake db:migrate behaving different for different environments

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:inexecute_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:incolumns’
C:/project/vendor/rails/activerecord/lib/active_record/base.rb:1220:in
columns' C:/project/vendor/rails/activerecord/lib/active_record/base.rb:1239:incontent_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:inacts_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:inrequire’
C:/project/vendor/rails/activesupport/lib/active_support/
dependencies.rb:148:in require' C:/project/vendor/rails/activesupport/lib/active_support/ dependencies.rb:507:innew_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:inrequire_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:inconst_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:ingem_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:inrequire’
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:inrequire’
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:independ_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:inload_application_classes’
C:/project/config/…/vendor/rails/railties/lib/initializer.rb:363:in
each' C:/project/config/../vendor/rails/railties/lib/initializer.rb:363:inload_application_classes’
C:/project/config/…/vendor/rails/railties/lib/initializer.rb:361:in
each' C:/project/config/../vendor/rails/railties/lib/initializer.rb:361:inload_application_classes’
C:/project/config/…/vendor/rails/railties/lib/initializer.rb:182:in
process' C:/project/config/../vendor/rails/railties/lib/initializer.rb:112:insend’
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:ingem_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:inrequire’
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:inrequire’
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:inexecute’
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:inexecute’
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:insynchronize’
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:ininvoke_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:ininvoke_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:insynchronize’
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:ininvoke’
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:intop_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:intop_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:intop_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:instandard_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:inload’
C:/ruby/bin/rake:16

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

Hey Gourav,

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

-Ryan

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. [email protected]

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

-Gourav

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

Many thanks Fred :slight_smile:

I think this solution works fine for now.

On Dec 26, 4:57 pm, Frederick C. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs