add_column rails code example
Example 1: how to add column to table rails
rails g migration add_description_to_users description:string
rails db:migrate
Example 2: change column rails example
def change
change_column(:table_name, :column_name, :new_type)
end
Example 3: rails g migration add columns
$ rails generate migration AddDetailsToProducts part_number:string price:decimal
Example 4: activerecord add column
class AddPartNumberToProducts < ActiveRecord::Migration[6.0]
def change
add_column :products, :part_number, :string
end
end