Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add default value to a column being added through 'rails g migration' command

I know how to add default value in a migration file already created. i.e.,

`rails generate migration AddTestColumnToTesttable test_status:boolean` to create it.

It will generate this migration:

class AddTestColumnToTable < ActiveRecord::Migration
  def change
    add_column :table, :test_status, :boolean, :default => true
  end
end

But, Can we add the default value through rails g migration command itself?

like image 489
Rajesh Omanakuttan Avatar asked Mar 06 '14 06:03

Rajesh Omanakuttan


1 Answers

No, it can't be done from the command line, you need to change it in the migration file

add_column :table, :test_status, :boolean, :default => true

Hope that helps!

like image 110
Rajdeep Singh Avatar answered Oct 12 '22 09:10

Rajdeep Singh