views:

1184

answers:

2

We have script/generate migration add_fieldname_to_tablename fieldname:datatype syntax for adding new columns to a model.

On the same line, do we have a script/generate for changing the datatype of a column? Or should I write sql directly into my vanilla migration?

I want to change a column from datetime to date.

Thanks

+2  A: 

I think change_column :table_name, :column_name, :date should work.

Alex - Aotea Studios
i was hoping more of a script/generate migration route. change_column works fine in a standalone migration
papdel
@b_ayan: as far as I know, the only magical words in migration names are "add" and "remove".
Alex - Aotea Studios
Thanks Alex, my brief research tells me the same
papdel
A: 

You can also use a block if you have multiple columns to change within a table.

Example:

change_table :table_name do |t|
  t.change :column_name, :column_type, {options}
end

See the API documentation on the Table class for more details.

John