Ik_guy

Geekskillz_logo1


"Everything that boots is beautiful."


Aug 26
2008

Rake db:migrate Fails on nil.info

Tags: Programming   Ruby on Rails


I'm posting this so that it can be Googled by others having the same/similar problem.

In both Rails 1.2 and Rails 2.1 on Mac and Windows, I hit a problem in the ActiveRecord migration code which causes a database migration to abort. Here is the rake db:migrate --trace output:



Macintosh:geekblog me$ rake db:migrate --trace

(in /Users/me/rails/geekblog)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** has_many_polymorphs: rails environment detected
** has_many_polymorphs: preloading parent model Tag
** has_many_polymorphs: preloading parent model Tag
** Execute db:migrate
rake aborted!
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.info
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:421:in `migrate'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:420:in `each'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:420:in `migrate'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:357:in `up'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:340:in `migrate'
/Library/Ruby/Gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:99
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19


On line 421 of /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb, we find this:

Base.logger.info "Migrating to #{migration} (#{migration.version})"


At this point, Base.logger is always null (nil) in all my Rails projects, at versions 1.2 and 2.1, on Mac and Windows, in development and production environments. I don't know why... But the fix is simple. Change the above line so that it checks to see if the logger is null (which it should probably be doing):

Base.logger.info "Migrating to #{migration} (#{migration.version})" unless Base.logger.nil?


Since this "bug" has persisted for years, I assume this is a problem that others are not hitting. Logging works in my development and production environments, so logger should not be null in this case.

*shrug*

Life goes on.

Anyone else hitting this problem with rake db:migrate? Let me know so we can bond and so on.



StumbleUpon This! Bookmark This Article Digg This Story

  Matt Darby, on Tuesday, September 30, 2008 at 17:36 Eastern Daylight Time:
Same issue here as well. I also get a 'nil.debug' error when attempting to use the Populator gem suddenly. Meh. I don't like misbehaving plugins....
  Leland Thorpe, on Wednesday, October 29, 2008 at 20:23 Eastern Daylight Time:
Wow, thank you for posting this, as I did indeed wind up here via Google. I was frustrated, at first, because I'm using a shared server so I don't have control over the code; as a work-around, I ran

rake rails:freeze:gems

so that I was running rails out of vendor/plugins instead of the system-wide installation. Then I edited the line as described above, which makes my set-up now work. UUUUUUGLY, but I hope that (if more people find this post via Google) they may find this comment useful.
  Neil, on Thursday, October 30, 2008 at 09:54 Eastern Daylight Time:
I'm glad to hear that I'm not the only one hitting this problem.

Thanks for the work-around, Leland! I didn't know you could run rails out of your own plugins directory. Great tip!



Post a comment:

Name:
E-mail: (will not be sold or published)
Website: (Optional)

Your comment:

Are you human?
Please enter the
text in the picture:


About Me

ThinkGeek

Feed-icon Technorati


Loot For Geeks:
4inkjets Great Prices and Best Quality!
Man's Wig! All size heads! Handsome! Sideburns! Modacrylic Fiber!
Protection
!
Make money online selling grit! Famous men sell grit!