On 26 Dec 2008, at 21:07, Gourav Tiwari 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

>
> On Dec 26, 2:50 pm, Frederick Cheung <[email protected]>
> wrote:
>> On 26 Dec 2008, at 18:29, Gourav Tiwari wrote:
>>
>>
>>
>>
>>
>>> 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
>>
>> 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
>>
>>> 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
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to