0
0

【Rails】カラムのデフォルト値を変更する

Posted at

カラムのデフォルト値を変更するにはマイグレーションファイルに以下のように記述します。


def change
  change_column_default テーブル名, カラム名, from: 元のデフォルト値, to: 変更後のデフォルト値
end

usersテーブルのis_sampleカラムのデフォルト値をfalseからtrueに変更する場合は以下のようになります。


def change
  change_column_default :users, :is_sample, from: false, to: true
end

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0