nil.[] error when using Rails migrations

I just had a little trouble with Rails migrations. I was trying to add a column to a database table in the migration using:

[source language=":ruby"]add_column :condos, :product_id, :int, :null => false, :limit => ’11′[/source]

The syntax seems ok at first glance but it resulted in the following error:

[source language=":ruby"]
– add_column("condos", "product_id", "int")
rake aborted!
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
/usr/lib64/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:272:in `type_to_sql’
/usr/lib64/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:122:in `add_column’
[/source]

The type_to_sql should have given it away to me but I overlooked it at first and spun my wheels trying to figure out what was wrong. As it turned out :int is not right and I need to use :integer instead.

Comments are closed.