# Rake migrate error: nil.first

**URL:** <https://www.ruby-forum.com/t/rake-migrate-error-nil-first/101517>\
**Category:** Rails\
**Created:** [August 5, 2006, 6:00pm UTC](https://www.ruby-forum.com/t/rake-migrate-error-nil-first/101517 "2006-08-05T18:00:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [August 5, 2006, 6:00pm UTC](https://www.ruby-forum.com/t/rake-migrate-error-nil-first/101517/1 "2006-08-05T18:00:17Z")

</div>

My migrations were working fine until today. I dropped and re-created  
the  
database.But, when I go to apply my migrations, rake migrate aborts with  
this error.

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.first

Any idea what might be wrong? The migrations look right. It’s talking  
to  
the database ( I can see the new schema\_info table). I’m stumped on this  
one.

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [August 5, 2006, 6:39pm UTC](https://www.ruby-forum.com/t/rake-migrate-error-nil-first/101517/2 "2006-08-05T18:39:20Z")

</div>

On Sat, 2006-08-05 at 08:55 -0700, Larry K. wrote:

> this one.

* * *

add ‘–trace’ to the migrate command which should provide some  
meaningful information as to which line in your migration file is  
breaking/causing this

Craig

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [August 5, 2006, 6:45pm UTC](https://www.ruby-forum.com/t/rake-migrate-error-nil-first/101517/3 "2006-08-05T18:45:20Z")

</div>

Here is the trace output. But, I’m still not sure where I should be  
looking  
for the errors.  
-Larry

\*\* Invoke migrate (first\_time)  
\*\* Invoke db:migrate (first\_time)  
\*\* Invoke environment (first\_time)  
\*\* Execute environment  
\*\* Execute db:migrate  
rake aborted!  
You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.first  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active\_record/migration.rb:3  
57:in `migration_files' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/connection_ada pters/mysql_adapter.rb:189:in`sort\_by’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active\_record/migration.rb:3  
56:in `migration_files' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:3 39:in`migration\_classes’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active\_record/migration.rb:3  
27:in `migrate' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:2 94:in`up’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active\_record/migration.rb:2  
85:in `migrate' /usr/lib/ruby/gems/1.8/gems/rails-1.1.4/lib/tasks/databases.rake:4 /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in`execute’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in`invoke’  
/usr/lib/ruby/1.8/thread.rb:135:in `synchronize' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in`invoke’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:364:in  
`invoke_prerequisites' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:999:in`each’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:363:in  
`invoke_prerequisites' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:356:in`invoke’  
/usr/lib/ruby/1.8/thread.rb:135:in `synchronize' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in`invoke’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in`run’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7  
/usr/bin/rake:18

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [August 6, 2006, 3:22am UTC](https://www.ruby-forum.com/t/rake-migrate-error-nil-first/101517/4 "2006-08-06T03:22:12Z")

</div>

Thanks Damon,

I moved all the migrations out, re-created the db, and applied the  
migrations one by one. In the process, I discovered that some old svn  
changes had gotten mixed in with my migrations. Once, I cleared that  
up.  
the migrations ran as expected.  
-Larry

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [August 5, 2006, 9:09pm UTC](https://www.ruby-forum.com/t/rake-migrate-error-nil-first/101517/5 "2006-08-05T21:09:29Z")

</div>

Larry K. \<larry@…\> writes:

> Here is the trace output. But, I’m still not sure where I should be looking  
> for the errors. -Larry\*\* Invoke migrate (first\_time)\*\* Invoke db:migrate  
> (first\_time)\*\* Invoke environment (first\_time)\*\* Execute environment  
> \*\* Execute db:migraterake aborted!You have a nil object when you didn’t expect  
> it!You might have expected an instance of Array.The error occured while  
> evaluating nil.first/usr/lib/ruby/gems/1.8/gems/activerecord-  
> 1.14.3/lib/active\_record/migration.rb:3 57:in `migration\_files’

Here are the relevant lines from migration.rb:

355 def migration\_files  
356 files = Dir[“#{@migrations\_path}/[0-9]_\__.rb”].sort\_by do |f|  
357 migration\_version\_and\_name(f).first.to\_i  
358 end  
359 down? ? files.reverse : files  
360 end  
361  
362 def migration\_class(migration\_name)  
363 migration\_name.camelize.constantize  
364 end  
365  
366 def migration\_version\_and\_name(migration\_file)  
367 return _migration\_file.scan(/([0-9]+)\_([\_a-z0-9]_).rb/).first  
368 end

Line 357 is the problem line. So somehow when it is scanning your  
/db/migrate  
directory for relevant files, there is something in there that is not in  
the  
typical form of migration naming 001\_my\_migration.rb. Try clearing out  
any  
non-migration files from db/migrate and try again.

Good luck,  
-damon

> **[Damon Clinkscales](https://damonc.onuniverse.com/)**
>
> Damon Clinkscales

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [August 6, 2006, 3:50am UTC](https://www.ruby-forum.com/t/rake-migrate-error-nil-first/101517/6 "2006-08-06T03:50:28Z")

</div>

Larry K. wrote:

> Thanks Damon,
> 
> I moved all the migrations out, re-created the db, and applied the  
> migrations one by one. In the process, I discovered that some old svn  
> changes had gotten mixed in with my migrations. Once, I cleared that  
> up.  
> the migrations ran as expected.  
> -Larry

Most excellent.

-damon

> **[Damon Clinkscales](https://damonc.onuniverse.com/)**
>
> Damon Clinkscales
