Project

General

Profile

Actions

Bug #296

closed

Incorrect family_id references breaks migration

Added by Frank Sweetser over 14 years ago. Updated over 14 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
DB migrations
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

Upgrading to the latest 1.5 RC, and ran into this error when running db:migrate:

[root@jms foreman]# rake db:migrate --trace
(in /usr/share/foreman)
  • Invoke db:migrate (first_time)
  • Invoke environment (first_time)
  • Execute environment
  • Execute db:migrate
    CreateMediasOperatingsystemsAndMigrateData: migrating ===================
    rake aborted!
    An error has occurred, all later migrations canceled:

missing attribute: family_id
/usr/share/foreman/app/models/operatingsystem.rb:20:in `after_initialize'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/callbacks.rb:347:in `send'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/callbacks.rb:347:in `callback'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/base.rb:1657:in `send'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/base.rb:1657:in `instantiate_without_polymorphic_checks'
/usr/share/foreman/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/base.rb:52:in `instantiate'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/base.rb:661:in `find_by_sql'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/base.rb:661:in `collect!'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/base.rb:661:in `find_by_sql'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/base.rb:1548:in `find_every'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/base.rb:1505:in `find_initial'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/base.rb:692:in `exists?'
./db/migrate//20100523141204_create_medias_operatingsystems_and_migrate_data.rb:7:in `up_without_benchmarks'
./db/migrate//20100523141204_create_medias_operatingsystems_and_migrate_data.rb:5:in `each'
./db/migrate//20100523141204_create_medias_operatingsystems_and_migrate_data.rb:5:in `up_without_benchmarks'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `send'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:365:in `__send__'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:365:in `migrate'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:486:in `migrate'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:562:in `call'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:562:in `ddl_transaction'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:485:in `migrate'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:472:in `each'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:472:in `migrate'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:400:in `up'
/usr/share/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:383:in `migrate'
/usr/share/foreman/vendor/rails/railties/lib/tasks/databases.rake:116
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:635:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:635:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:630:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:630:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:238:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:589:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:582:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2050:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2028:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2028:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2028:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2067:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2022:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2000:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2067:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1997:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

Poking around, I found that the problem was references to family_id that should have been @family_id. Simple patch attached.


Files

Actions #1

Updated by Ohad Levy over 14 years ago

  • Category set to DB migrations
  • Assignee set to Ohad Levy
  • Target version set to 0.1-5

this does not make any sense to me (as @family_id is not defined anywhere).

maybe a simple rescue statement in that method should be done (e.g. if it failed to load the family data)

Actions #2

Updated by Frank Sweetser over 14 years ago

Actually, ignore that previous patch, as digging more it's completely wrong. This one seems to work better for me.

Actions #3

Updated by Ohad Levy over 14 years ago

did you had a chance to remigrate your original data?
the defined? was part of the original patch, which I fixed a while ago with respond_to.

I see no damage in including this patch, just based on past experience, I'm not sure if that's the root cause.

maybe add a rescue to be on the safe side? :)

Thanks,
Ohad

Actions #4

Updated by Frank Sweetser over 14 years ago

Yes, I rolled back to my pre-1.5 database snapshot and re-ran the migrations from scratch. So far, it Works For Me.

My ruby-fu is far to weak to know if the defined? is the best solution or not. If it helps, I can reproduce the problem quickly in irb:

[root@jms foreman]# ./script/console
Loading production environment (Rails 2.3.5)

Operatingsystem.exists?(1)

ActiveRecord::MissingAttributeError: missing attribute: family_id

With the defined?, this works and returns true.

Actions #5

Updated by Ohad Levy over 14 years ago

  • Status changed from New to Ready For Testing
  • Assignee set to Ohad Levy

ok, I'll play a bit more and merge soon :)

Actions #6

Updated by Ohad Levy over 14 years ago

  • Target version set to 0.1-5
Actions #7

Updated by Frank Sweetser over 14 years ago

  • % Done changed from 0 to 100
Actions #8

Updated by Ohad Levy over 14 years ago

  • Status changed from Ready For Testing to Closed
Actions

Also available in: Atom PDF