I've encountered a strange problem migrating a database in production mode.
The initial rake db:migrate
fails with error "Object is not missing Constant User", where User is one of my Models, that is accessed in this migration like this:
add_column :users, :feedbacks_count, :integer, :default => 0
User.reset_column_information
User.all.each do |u|
u.update_attribute :feedbacks_count, u.feedbacks.length
end
end
The logs say the following:
Object is not missing constant User!
/var/lib/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:417:in `load_missing_constant'
/var/lib/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:80:in `const_missing_not_from_s3_library'
/var/lib/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
/var/lib/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:92:in `const_missing'
/var/lib/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:98:in `send'
/var/lib/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:98:in `const_missing'
./db/migrate//20100823185519_add_columns_for_counter_caches.rb:5:in `up_without_benchmarks'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:282:in `send'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:282:in `migrate'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:282:in `migrate'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:365:in `send'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:365:in `migrate'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:486:in `migrate'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:562:in `call'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:562:in `ddl_transaction'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:485:in `migrate'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:472:in `each'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:472:in `migrate'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:400:in `up'
/var/lib/gems/1.8/gems/activerecord-2.3.4/lib/active_record/migration.rb:383:in `migrate'
/var/lib/gems/1.8/gems/rails-2.3.4/lib/tasks/databases.rake:116
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/var/lib/gems/1.8/gems/rake-0.8.7/bin/rake:31 /usr/bin/rake:19:in `load'
/usr/bin/rake:19
I read about a lot of articles, referring to "Object is not missing Constant X" where the problem mainly is referencing models by lazy_loading or accessing plugins.
Requiring the 'user.rb' before the add_column or adding a User.new
before accessing the users table does not resolve the problem.
Accessing the User model in a migration before the failing one does not cause any trouble either.
Most strange thing about the issue is, that i migrated the same code one day ago to another server, with the same settings and in production as well, where the migration ran without any trouble.
any help would be apreciated!