B'more on Rails Message Board › Code problem

Code problem

David R.
David_Robson
Baltimore, MD
Post #: 2
WhatDoYaThink? Is it OK to post code questions here?


What am I doing wrong? I am trying to add a column to an existing MySQL table 'classifieds' with the migration code below...keep getting the message:

rake aborted!
You have a nil object when you didn't expect it!

- - - - - - - - - - -

class AddCategoryIDtoClassifieds < ActiveRecord::Migration
..def self.up
....add_column "classifieds", "category_id", :integer
..end

..def self.down
....remove_column "classifieds", "category_id"
..end
end

- - - - - - - - - - -

This syntax yielded the same result:

- - - - - - - - - - -

class AddCategoryIDtoClassifieds < ActiveRecord::Migration
..def self.up
....add_column :classifieds, :category_id, :integer
..end

..def self.down
....remove_column :classifieds, :category_id
..end
end

- - - - - - - - - - -
George A.
user 3366585
Baltimore, MD
Post #: 2
Hi Dave,

Post the full trace so we can see the exact error:

rake migrate --trace

Thx,

George
Mike S.
subelsky
Baltimore, MD
Post #: 6
and also the output of ruby -v and what version of Rails you are using.
David R.
David_Robson
Baltimore, MD
Post #: 3
Ruby version: 1.8.5
Rails version: 1.2.2

The migrate --trace generated quite a list of text...I don't know how to capture a Win DOS console output to a text file so I took a screen shot which is now in the "Files' section of this forum...titled 'Migrate_Trace_1.jpg'.

Dave
David R.
David_Robson
Baltimore, MD
Post #: 4

I took a screen shot which is now in the "Files' section of this forum...titled 'Migrate_Trace_1.jpg'.

Forget that screen shot...the trace is below.
Dave


C:\rails\railslist>rake db:migrate --trace
(in C:/rails/railslist)
** 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 occurred while evaluating nil.first
c:/ruby/lib/ruby/gems/1.8/gems/activer­ecord-1.15.2/lib/active_record/migration­.r
b:360:in `migration_files'
c:/ruby/lib/ruby/gems/1.8/gems/activer­ecord-1.15.2/lib/active_record/connectio­n_
adapters/mysql_adapter.rb:248:in `sort_by'
c:/ruby/lib/ruby/gems/1.8/gems/activer­ecord-1.15.2/lib/active_record/migration­.r
b:359:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/activer­ecord-1.15.2/lib/active_record/migration­.r
b:359:in `sort_by'
c:/ruby/lib/ruby/gems/1.8/gems/activer­ecord-1.15.2/lib/active_record/migration­.r
b:359:in `migration_files'
c:/ruby/lib/ruby/gems/1.8/gems/activer­ecord-1.15.2/lib/active_record/migration­.r
b:342:in `migration_classes'
c:/ruby/lib/ruby/gems/1.8/gems/activer­ecord-1.15.2/lib/active_record/migration­.r
b:330:in `migrate'
c:/ruby/lib/ruby/gems/1.8/gems/activer­ecord-1.15.2/lib/active_record/migration­.r
b:297:in `up'
c:/ruby/lib/ruby/gems/1.8/gems/activer­ecord-1.15.2/lib/active_record/migration­.r
b:288:in `migrate'
c:/ruby/lib/ruby/gems/1.8/gems/rails-1­.2.2/lib/tasks/databases.rake:4
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.­7.1/lib/rake.rb:387:in `call'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.­7.1/lib/rake.rb:387:in `execute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.­7.1/lib/rake.rb:387:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.­7.1/lib/rake.rb:387:in `execute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.­7.1/lib/rake.rb:357:in `invoke'
c:/ruby/lib/ruby/1.8/thread.rb:135:in `synchronize'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.­7.1/lib/rake.rb:350:in `invoke'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.­7.1/lib/rake.rb:1906:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.­7.1/lib/rake.rb:1906:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.­7.1/lib/rake.rb:1906:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.­7.1/bin/rake:7
c:/ruby/bin/rake.bat:20:in `load'
c:/ruby/bin/rake.bat:20
George A.
user 3366585
Baltimore, MD
Post #: 3

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.first
c:/ruby/lib/ruby/gems/1.8/gems/activer­ecord-1.15.2/lib/active_record/migration­.r
b:360:in `migration_files'

It looks as if Rails is checking for migration files and can't find any. By convention it looks in [RAILS_ROOT]/db/migrate, and it looks for file names with the format number(s)_letters.rb (e.g. 083_change_problem_addressed_by_user_id_­to_closed.rb).

Did you used the migration generator (ruby script/generate migration ChangeFooToBar) to create the migration file or did you create it manually?

Where in your directory structure is the migration file? What is its name?
David R.
David_Robson
Baltimore, MD
Post #: 5
>Did you used the migration generator (ruby script/generate migration ChangeFooToBar)
>to create the migration file or did you create it manually?

Welllll...I can't remember. But I agree...I must have somehow got the migration files out of synch.

I just rebuilt the app from scratch while strictly using the commands 'generate model' and 'generate migration'. It went smoothly without repetition of the above error.

I'm not sure what caused the error, but I'm ready to leave it behind.

Thanks!
George A.
user 3366585
Baltimore, MD
Post #: 4
Excellent. Fire away with any other questions you might have.
Powered by mvnForum

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy