Migration Issue

I’m following along with the example in Agile, and I’m simply trying to
create a migration to add a price column to a table called products.
This table exists as my application is displaying it using a scaffold.
Here’s my migration:

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

However when I run my migration I get the following:

powerbook-g4-15:~/Documents/work/depot drew$ rake db:migrate
(in /Users/drew/Documents/work/depot)
== AddPrice: migrating

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

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

Any help would be great… I feel like a moron, I’m sure I’ve gotten
this working before, just trying to follow along with the example in the
book.

You need to update to Rails 1.2 RC 1. Since the book relies on edge,
that’s where you can fix your issue.

gem install rails --source http://gems.rubyonrails.org
–include-dependencies

is the code to run

For more info:

Hi, could you post your migration file?

-Conrad

Hi, I see it.

-C

boboroshi wrote:

You need to update to Rails 1.2 RC 1. Since the book relies on edge,
that’s where you can fix your issue.

gem install rails --source http://gems.rubyonrails.org
–include-dependencies

is the code to run

For more info:
Ruby on Rails — Rails 1.2: Release Candidate 1

I am running this from inside locomotive, so I attempted to update my
rails install inside locomotive by doing the following:

gem update rails --source http://gems.rubyonrails.org
–include-dependencies

However, now when I do rails -v, I see:

powerbook-g4-15:~/Documents/work/depot drew$ rails -v
Rails 1.1.6

Still getting the same error as well…

Drew, Agile v2 requires edge/1.2. I don’t think there’s any way around
it. I would reccomend following Dan Benjamin’s phenomenal step by step
directions here:

and run it that way. It will return as 1.1.6 from shell, but do a gem
list to verify you’re on edge.

soho:~ jathayde$ rails -v
Rails 1.1.6

and you’ll see “1.1.6.5618” as the version number.

soho:~ jathayde$ gem list

*** LOCAL GEMS ***

actionmailer (1.2.5.5618, 1.2.5)
Service layer for easy email delivery and testing.

actionpack (1.12.5.5618, 1.12.5)
Web-flow and rendering framework putting the VC in MVC.

actionwebservice (1.1.6.5618, 1.1.6)
Web service support for Action Pack.

activerecord (1.14.4.5618, 1.14.4)
Implements the ActiveRecord pattern for ORM.

activesupport (1.3.1.5618, 1.3.1)
Support and utility classes used by the Rails framework.

rails (1.1.6.5618, 1.1.6)
Web-application framework with template engine, control-flow layer,
and ORM.

EnjoY!

boboroshi wrote:

Drew, Agile v2 requires edge/1.2. I don’t think there’s any way around
it. I would reccomend following Dan Benjamin’s phenomenal step by step
directions here:

Bob -

Thanks for the help thus far. I do indeed now have Raisl edge/1.2
installed. However I am receiving the very same error I first discussed.
Here’s my full trace:

drew-olsons-powerbook-g4-15:~/Documents/work/depot drew$ rake db:migrate
–trace
(in /Users/drew/Documents/work/depot)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== AddPrice: migrating

– add_column(:products, :price, :decimal, {:precision=>8, :default=>0,
: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.[]
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:259:in
type_to_sql' /Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:122:inadd_column’
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:273:in
method_missing' /Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:257:insay_with_time’
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/1.8/benchmark.rb:293:in
measure' /Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:257:insay_with_time’
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/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:inreal_up’
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:210:in
migrate' /Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/1.8/benchmark.rb:293:inmeasure’
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:210:in
migrate' /Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:333:inmigrate’
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:328:in
migrate' /Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:295:inup’
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:286:in
migrate' /Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/tasks/databases.rake:4 /Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:inexecute’
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in
execute' /Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:ininvoke’
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/1.8/thread.rb:135:in
synchronize' /Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:ininvoke’
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in
run' /Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:inrun’
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7
/Applications/Locomotive2/Bundles/rmagickRailsSept2006_ppc.locobundle/framework/bin/rake:18
drew-olsons-powerbook-g4-15:~/Documents/work/depot drew$