想通过迁移更改表中的columntype

时间:2011-03-29 07:37:26

标签: ruby-on-rails-3

您好我有一个表格,其中有两列来自和来自类型datatime我希望将数据类型从datetime更改为date。我不知道像rails g

这样的迁移中的chagning列类型的确切命令

2 个答案:

答案 0 :(得分:8)

从命令行运行:

rails generate migration change_data_type_for_table_column

将您的迁移写为:

change_table :table do |t|  
  t.change :column, :type 
end

答案 1 :(得分:2)

使用change_column

change_column(:table, :column, :date)