rails add migration code example

Example 1: Add references rails migration

rails g migration AddUserToUploads user:references

Example 2: Add references rails migration

class AddUserToUploads < ActiveRecord::Migration
  def change
    add_reference :uploads, :user, index: true
  end
end

Example 3: how create migration rails

rails g migration AddPartNumberToProducts

Example 4: rails g migration add columns

$ rails generate migration AddDetailsToProducts part_number:string price:decimal

Example 5: activerecord add column

class AddPartNumberToProducts < ActiveRecord::Migration[6.0]
  def change
    add_column :products, :part_number, :string
  end
end

Example 6: ruby on rails db migrate

rails db:migrate

Tags:

Misc Example