I have this error message and don't know what to do

I am a newibie on ruby on the rails. I was following a book example and
has the follow exactly code shows on the book:
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

And then I got the following error message:
== AddPrice: migrating

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

I have no idea what went wrong. Can anybody help me?
Thanks!

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

This looks fine - and works on my machine.
Try running with trace:

rake db:migrate --trace

I just had the exact same problem at apparently the exact same time.
Working from the Agile book. Let me know if you figure it out and I’ll
do the same.

thx
J

What version of rake are you using? (do rake --version)

Here is the trace:

(in /home/yan/workspace/depot)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== AddPrice: migrating

– add_column(:products, :price, :decimal, {:scale=>2, :default=>0,
:precision=>8})
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.[]
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:259:in
type_to_sql' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:122:inadd_column’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:273:in
send' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:273:inmethod_missing’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:257:in
say_with_time' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:257:in
say_with_time' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:271:inmethod_missing’
./db/migrate//002_add_price.rb:3:in real_up' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:210:insend’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:210:in
migrate' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:210:in
migrate' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:333:inmigrate’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:328:in
each' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:328:inmigrate’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:295:in
up' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:286:inmigrate’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/tasks/databases.rake:4
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in call' /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 each' /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:357:in invoke' /usr/lib/ruby/1.8/thread.rb:135:insynchronize’
/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:inrun’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in each' /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:in `load’
/usr/bin/rake:18

toby privett wrote:

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

This looks fine - and works on my machine.
Try running with trace:

rake db:migrate --trace

rake version 0.7.1

I forgot to mention I am using it on Fedora 6 if it matters.

On Jan 26, 2007, at 12:14 PM, Yan wrote:

I am a newibie on ruby on the rails. I was following a book example
and
has the follow exactly code shows on the book:
class AddPrice < ActiveRecord::Migration
def self.up
add_column :products, :price, :decimal, :precision => 8, :scale
=> 2,

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

I have no idea what went wrong. Can anybody help me?

Update to Rails 1.2

Dave

Update to Rails 1.2

Dave

Thanks a lot!
It was the problem!
Now it working perfectly.

I don’t think rails 1.1.6 supports decimal types but 1.2.1 is supposed
to

You probably need to upgrade rails and your app

Craig

On Fri, 2007-01-26 at 20:48 +0100, Yan wrote:

:precision=>8})
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:273:in
send' migrate’
/usr/lib/ruby/1.8/thread.rb:135:in `synchronize’

end

This looks fine - and works on my machine.
Try running with trace:

rake db:migrate --trace


Craig W. [email protected]