Rake migrate error: nil.first

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.

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

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:insort_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:inmigration_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:inup’
/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:inexecute’
/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:ininvoke’
/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:ininvoke’
/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:ineach’
/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:ininvoke’
/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:ininvoke’
/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:inrun’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7
/usr/bin/rake:18

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

Larry K. <[email protected]…> 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
http://damonclinkscales.com/

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
http://damonclinkscales.com/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs