People,
I’m looking at the migrate example on p 74 of the rails2.pdf
It’s a simple example of using a migration to add a column to
the products table.
Here is a copy of the migration file named 002_add_price.rb
after I generated and then edited it:
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
I see this error when I walk through the demo:
bash mac maco /pt/books/rails2_my_depot/depot 9 $
bash mac maco /pt/books/rails2_my_depot/depot 9 $ rake db:migrate
–trace
(in /pt/books/rails2_my_depot/depot)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== AddPrice: migrating
– add_column(:products, :price, :decimal, {:precision=>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.[]
/r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:259:in
type_to_sql' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/connection_adapters/postgresql_adapter.rb:310:in
add_column’
/r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:272:in
method_missing' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:256:in
say_with_time’
/r/lib/ruby/1.8/benchmark.rb:293:in measure' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:256:in
say_with_time’
/r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:270:in
method_missing' ./db/migrate//002_add_price.rb:3:in
real_up’
/r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:210:in
migrate' /r/lib/ruby/1.8/benchmark.rb:293:in
measure’
/r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:210:in
migrate' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:332:in
migrate’
/r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:327:in
migrate' /r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:294:in
up’
/r/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/migration.rb:285:in
migrate' /r/lib/ruby/gems/1.8/gems/rails-1.1.4/lib/tasks/databases.rake:4 /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in
execute’
/r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in execute' /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in
invoke’
/r/lib/ruby/1.8/thread.rb:135:in synchronize' /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in
invoke’
/r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in run' /r/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in
run’
/r/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7
/r/bin/rake:18
bash mac maco /pt/books/rails2_my_depot/depot 10 $
bash mac maco /pt/books/rails2_my_depot/depot 10 $
bash mac maco /pt/books/rails2_my_depot/depot 10 $
Info about my setup:
bash mac maco /pt/books/rails2_my_depot/depot 12 $
bash mac maco /pt/books/rails2_my_depot/depot 12 $
bash mac maco /pt/books/rails2_my_depot/depot 12 $ uname -a
Darwin mac 8.7.0 Darwin Kernel Version 8.7.0: Fri May 26 15:20:53 PDT
2006;
root:xnu-792.6.76.obj~1/RELEASE_PPC Power Macintosh powerpc
bash mac maco /pt/books/rails2_my_depot/depot 13 $
bash mac maco /pt/books/rails2_my_depot/depot 13 $
bash mac maco /pt/books/rails2_my_depot/depot 13 $
[ os x 10.4 ]
bash mac maco /pt/books/rails2_my_depot/depot 19 $
bash mac maco /pt/books/rails2_my_depot/depot 19 $
bash mac maco /pt/books/rails2_my_depot/depot 19 $
bash mac maco /pt/books/rails2_my_depot/depot 19 $ psql
depot_development
Welcome to psql 8.1.4, the PostgreSQL interactive terminal.
bash mac maco /pt/books/rails2_my_depot/depot 12 $
bash mac maco /pt/books/rails2_my_depot/depot 12 $
bash mac maco /pt/books/rails2_my_depot/depot 12 $
bash mac maco /pt/books/rails2_my_depot/depot 12 $
bash mac maco /pt/books/rails2_my_depot/depot 11 $ gem list --local
*** LOCAL GEMS ***
actionmailer (1.2.3)
Service layer for easy email delivery and testing.
actionpack (1.12.3)
Web-flow and rendering framework putting the VC in MVC.
actionwebservice (1.1.4)
Web service support for Action Pack.
activerecord (1.14.3)
Implements the ActiveRecord pattern for ORM.
activesupport (1.3.1)
Support and utility classes used by the Rails framework.
postgres (0.7.1)
The extension library to access a PostgreSQL database from Ruby.
rails (1.1.4)
Web-application framework with template engine, control-flow layer,
and ORM.
rake (0.7.1)
Ruby based make-like utility.
sources (0.0.1)
This package provides download sources for remote gem installation
bash mac maco /pt/books/rails2_my_depot/depot 12 $
bash mac maco /pt/books/rails2_my_depot/depot 12 $
bash mac maco /pt/books/rails2_my_depot/depot 12 $
bash mac maco /pt/books/rails2_my_depot/depot 12 $
Anyone have any clues on how I can get this to work?
Thanks,
-Dan