Priyanshu0007
Priyanshu0007

Reputation: 23

Add and Change the default value for table column with migration

I currently have a migration and I simply want to add a couple more values to this migration such as to_limit and from_limit along with their default values (5&10). How should i do this?

class AddUserToCompany < ActiveRecord::Migration
  def change
    add_column :companies, :user, :jsonb, default: {"to_dist"=>50, "from_dist"=>70, "trs_one"=>100,   "trs_two"=>120}
  end
end 

I added some changes which also requires "to_limit"=>5 and "from_limit"=>10. Please suggest on how to add a new migrate file and add the changes.

Rails version - 4.2.11

This is my first time working with a rails application. So i am really confused on how to proceed with this.

Upvotes: 0

Views: 127

Answers (1)

Hemangini Gohel
Hemangini Gohel

Reputation: 151

1.If this changes are in progress (not already used by other) then you can rollback this migration by command

  • rollback last migration

rake db:rollback STEP=1

  • In order to rollback ONLY ONE specific migration

rake db:migrate:down VERSION=20220905201547

and after applying changes, run rake db:migrate

  1. If migration was created earlier then you can create new migration to apply your changes
  • generate new migration by command

rails generate migration nameOfMigration

I hope this helps

Upvotes: 1

Related Questions