LoginSignup
18
12

More than 5 years have passed since last update.

後からデフォルト値を追加する

Posted at

以下のようなマイグレーションを書く。

add_default_age_to_user.rb
class AddDefaultAgeToUser < ActiveRecord::Migration
  def change
     change_column :users, :age, :integer, :default => 30
  end
end

もちろんdb:migrate以前に追加したエントリについてはデフォルト値は適用されない。

18
12
1

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
18
12