Rails complaining of nil object and aborting

Hello all,

I am running into an issue where I am trying to do a db:migrate after
adding a price column to my database. Can anyone tell me what I can do
to fix this… I’m trying to learn this so my debugging skills aren’t
so great.

I have done the following:

  1. [[email protected]2 ~/depot]$ ruby script/generate migration add_price

  2. Edited the file:
    ====================
    [[email protected] ~/depot]$ vi /db/migrate/002_add_price.rb

Added the following lines:

class AddPrice < ActiveRecord::Migration def self.up add_column
:products, :price, :decimal, :precision => 8, :scale => 2, :default =>
0 end def self.down remove_column :products, :price end end

  1. [[email protected] ~/depot]$ rake db:migrate

(in /home/lem/depot)
== AddPrice: migrating

– add_column(roducts, rice, :decimal, {recision=>8, :scale=>2,
:default=>0})
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.[]

(See full trace by running task with --trace)

[[email protected] ~/depot]

Here is what I got when I ran the trace:

C:\Documents and Settings\Administrator\work\depot>rake db:migrate
–trace
(in C:/Documents and Settings/Administrator/work/depot)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== AddPrice: migrating

– add_column(:products, :price, :decimal, {:default=>0, :precision=>8,
:scale=>
2})
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.[]
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_
adapters/abstract/schema_statements.rb:259:in type_to_sql' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_ adapters/abstract/schema_statements.rb:122:inadd_column’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.r
b:273:in method_missing' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.r b:257:insay_with_time’
c:/ruby/lib/ruby/1.8/benchmark.rb:293:in measure' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.r b:257:insay_with_time’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.r
b:271:in method_missing' ./db/migrate//002_add_price.rb:3:inreal_up’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.r
b:210:in migrate' c:/ruby/lib/ruby/1.8/benchmark.rb:293:inmeasure’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.r
b:210:in migrate' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.r b:333:inmigrate’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.r
b:328:in migrate' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.r b:295:inup’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.r
b:286:in migrate' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/tasks/databases.rake:4 c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:inexecute’
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:ininvoke’
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:ininvoke’
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:inrun’
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7
c:/ruby/bin/rake.bat:25

I am getting the same thing. Dave T. is saying you need to be
running Rails 1.2.1 for this to work properly or Edge Rails.

I am running Rails 1.2.1 and I still get the error. It appears the
problem lies with how Rails is interpreting :decimals.

I am still looking for the fix for this. If I find it, I will post it
here.

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