<?xml version="1.0" encoding="UTF-8"?>
<article>
  <comments-count type="integer">3</comments-count>
  <created-at type="datetime">2008-08-26T15:57:00-04:00</created-at>
  <digg-bodytext>Article summary</digg-bodytext>
  <digg-topic>tech_news</digg-topic>
  <id type="integer">61</id>
  <month type="integer">8</month>
  <permalink>rake-db-migrate-fails-on-nil-info</permalink>
  <text>I'm posting this so that it can be Googled by others having the same/similar problem.&lt;br/&gt;&lt;br/&gt;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:&lt;br/&gt;&lt;br/&gt;&lt;split/&gt;&lt;br/&gt;&lt;br/&gt;[code]Macintosh:geekblog me$ rake db:migrate --trace&lt;br/&gt;(in /Users/me/rails/geekblog)&lt;br/&gt;** Invoke db:migrate (first_time)&lt;br/&gt;** Invoke environment (first_time)&lt;br/&gt;** Execute environment&lt;br/&gt;** has_many_polymorphs: rails environment detected&lt;br/&gt;** has_many_polymorphs: preloading parent model Tag&lt;br/&gt;** has_many_polymorphs: preloading parent model Tag&lt;br/&gt;** Execute db:migrate&lt;br/&gt;rake aborted!&lt;br/&gt;You have a nil object when you didn't expect it!&lt;br/&gt;[b]The error occurred while evaluating nil.info[/b]&lt;br/&gt;[b]/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:421:in `migrate'[/b]&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:420:in `each'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:420:in `migrate'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:357:in `up'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:340:in `migrate'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:99&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'&lt;br/&gt;/Library/Ruby/Gems/1.8/gems/rake-0.8.1/bin/rake:31&lt;br/&gt;/usr/bin/rake:19:in `load'&lt;br/&gt;/usr/bin/rake:19&lt;br/&gt;[/code]&lt;br/&gt;&lt;br/&gt;On line 421 of /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb, we find this:&lt;br/&gt;&lt;br/&gt;[code]Base.logger.info "Migrating to #{migration} (#{migration.version})"[/code]&lt;br/&gt;&lt;br/&gt;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):&lt;br/&gt;&lt;br/&gt;[code]Base.logger.info "Migrating to #{migration} (#{migration.version})" unless Base.logger.nil?[/code]&lt;br/&gt;&lt;br/&gt;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.&lt;br/&gt;&lt;br/&gt;*shrug*&lt;br/&gt;&lt;br/&gt;Life goes on.&lt;br/&gt;&lt;br/&gt;Anyone else hitting this problem with rake db:migrate? Let me know so we can bond and so on.</text>
  <title>Rake db:migrate Fails on nil.info</title>
  <updated-at type="datetime">2008-09-12T00:37:48-04:00</updated-at>
  <user-id type="integer">1</user-id>
  <year type="integer">2008</year>
</article>
