yan
January 26, 2007, 6:14pm
1
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!
yan
January 26, 2007, 7:52pm
2
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
yan
January 26, 2007, 8:00pm
3
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
yan
January 26, 2007, 8:42pm
4
What version of rake are you using? (do rake --version)
yan
January 26, 2007, 8:48pm
5
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:in
add_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:in
method_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:in
measure’
/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:in
method_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:in
send’
/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:in
measure’
/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:in
migrate’
/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:in
migrate’
/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:in
migrate’
/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:in
execute’
/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: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:1906:in
run’
/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:in
run’
/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
yan
January 26, 2007, 8:49pm
7
I forgot to mention I am using it on Fedora 6 if it matters.
yan
January 26, 2007, 8:56pm
8
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
yan
January 26, 2007, 9:04pm
9
Update to Rails 1.2
Dave
Thanks a lot!
It was the problem!
Now it working perfectly.
yan
January 26, 2007, 10:47pm
10
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]