以下を実行script/rails generate migration UpdateTimeFields
して使用します。(方法もありますがchange_column
、データを保持したまま、int列をdatetime列に変更できるとは思いません)。
class UpdateTimeFields < ActiveRecord::Migration
def self.up
rename_column :projects, :start_time, :old_start_time
rename_column :projects, :end_time, :old_end_time
add_column :projects, :start_time, :datetime
add_column :projects, :end_time, :datetime
# If applicable, insert code to iterate through your existing
# records and update the new start_time and end_time fields
# based on your int data.
remove_column :projects, :old_start_time
remove_column :projects, :old_end_time
end
def self.down
# do the opposite of above: rename the datetime fields, create the int
# fields again, migrate the data back into the int fields, and delete
# the datetime fields.
end
end