0

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

The migration was created earlier so i will have to generate a new migration. I am a little confused regarding it. During the new migration do i add only the new details that i want to add or all of them including the existing ones. Need a small clarification regarding this. Thankyou
you can use change_column_default :articles, :user, from: {"to_dist"=>50, "from_dist"=>70, "trs_one"=>100, "trs_two"=>120}, to: {"to_dist"=>50, "from_dist"=>70, "trs_one"=>100, "trs_two"=>120, "new_att" => 10} I guess you need to pass all params as we can replace full the value(but may not be change anything with current value) @Priyanshu0007

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.