# Add\_column failing migration

**URL:** <https://www.ruby-forum.com/t/add-column-failing-migration/68805>\
**Category:** Rails\
**Created:** [September 15, 2006, 3:38pm UTC](https://www.ruby-forum.com/t/add-column-failing-migration/68805 "2006-09-15T15:38:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [September 15, 2006, 3:38pm UTC](https://www.ruby-forum.com/t/add-column-failing-migration/68805/1 "2006-09-15T15:38:26Z")

</div>

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:in`add\_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: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//004_add_sellable_location_fields.rb:7:in`real\_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: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  
`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`execute’  
/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`run’  
/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

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [September 15, 2006, 6:45pm UTC](https://www.ruby-forum.com/t/add-column-failing-migration/68805/2 "2006-09-15T18:45:00Z")

</div>

> 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](http://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.

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [September 15, 2006, 8:45pm UTC](https://www.ruby-forum.com/t/add-column-failing-migration/68805/3 "2006-09-15T20:45:13Z")

</div>

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
