環境
- Ruby: 2.6.3
- Rails: 5.2.3
- PostgreSQL: 9.6
書き方
class ChangeColumnsToUser < ActiveRecord::Migration[5.2]
def up
change_column :users, :birthday, :date, using: "birthday::date", comment: "生年月日"
change_column :users, :sex, :integer, using: "sex::integer", comment: "性別"
end
def down
change_column :users, :birthday, :text, comment: "生年月日"
change_column :users, :sex, :text, comment: "性別"
end
end
補足
usingオプションを付けないとこのようなメッセージが表示され、マイグレーションが失敗します。
HINT: You might need to specify "USING birthday::date".