Migration Issue


#1

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.


#2

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:


#3

Hi, could you post your migration file?

-Conrad


#4

Hi, I see it.

-C


#5

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:
http://weblog.rubyonrails.org/2006/11/23/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…


#6

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:

http://hivelogic.com/articles/2005/12/01/ruby_rails_lighttpd_mysql_tiger

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!


#7

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$