Запустите 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