varchar attribute with migration

I can't seem to find this anywhere... How would I define the number in varchar(#) with the migration tool. By default when using :string it sets it at 255. Probably a really simple answer to this, thanks for the help.

:limit => n

Take a look at :limit.

add_column :your_table, :your_column, :string, :limit => 20

This page from the Rails API lists all the options.[

ActiveRecord::ConnectionAdapters::TableDefinition](ActiveRecord::ConnectionAdapters::TableDefinition)

Aaron

I can't seem to find this anywhere... How would I define the number in varchar(#) with the migration tool. By default when using :string it sets it at 255. Probably a really simple answer to this, thanks for the help.

There's a reason that it defaults to 255. Because for the vast majority of cases, it Just Doesn't Matter. It's not worth dedicating brain cycles to try to figure out what the optimal size of a field is. Especially not with varchar, which automatically contracts and expands any way. You'll usually guess too low anyway and then later have to change it.

David Heinemeier Hansson

thanks for the help and advice...

-salo