Add_column failing migration

i’m not sure if i just completely screwed up my migrations or not… i
get this error when i try to migrate either up or down from the current
version (going either way adds a column and gives the same error)…
dropping a column seems to be work fine. here’s the trace:

[stuart@unitest stuart]$ rake db:migrate VERSION=4 --trace
(in /home/ruby/stuart)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== AddSellableLocationFields: migrating

– add_column(:inventory, :SellAtHome, :int)
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
method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:257:insay_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:insay_with_time’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:271:in
method_missing' ./db/migrate//004_add_sellable_location_fields.rb:7:inreal_up’
/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
migrate' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:295:inup’
/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:inexecute’
/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:ininvoke’
/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:ininvoke’
/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:inrun’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7
/usr/bin/rake:18

the line that fails is add_column :inventory, :SellAtHome, :int
this is the first line of the up method.

i’ve had some small problems with migrations in the past, but the other
times i was able to figure out what was going wrong… thanks in advance

stuart

i’m not sure if i just completely screwed up my migrations or
not… i get this error when i try to migrate either up or
down from the current version (going either way adds a column
and gives the same error)…
dropping a column seems to be work fine. here’s the trace:

Here’s the part that’s the key:

/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_rec
ord/connection_adapters/abstract/schema_statements.rb:259:in
type_to_sql' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_rec ord/connection_adapters/abstract/schema_statements.rb:122:in add_column’

It had problems converting the type (:int) to sql when adding the
column. So I went to the docs at api.rubyonrails.com, and under
ActiveRecord::Migration docs for add_column, it says this:

] add_column(table_name, column_name, type, options):
] Adds a new column to the table called table_name named
] column_name specified to be one of the following types:
] :string, :text, :integer, :float, :datetime, :timestamp,
] :time, :date, :binary, :boolean. A default value can be
] specified by passing an options hash like { :default =>
] 11 }.

So it looks like you should try :integer instead of :int.

  • Mark.

yup, that did it… thanks for the help. i did note that :integer was
used, but i also saw :int (in the create table blocks for migration)
and i thought they were interchangeable… good to know they really
aren’t.

stuart