Dynamo
Dynamo

Reputation: 77

Ruby on Rails: How to migrate changes after adding validation on models?

I'm new to Ruby on Rails and I'm currently working on models. I have added a new validation to pre created attribute.

This is the validation that I have added.

validates_presence_of :services, :message => 'This field is non-editable'

Do I have to migrate the changes after adding validation? If yes then how?

Any kind of help would be greatly appreciated.

Upvotes: 0

Views: 363

Answers (1)

brcebn
brcebn

Reputation: 1722

Records already in your database won't be affected. But it you edit a previous record, you won't be able to store it without passing the validation.

You've 3 options:

  • On edit/update, force new field value (default in your case)
  • Create a migration to set default value on the column.
  • Create a migration to update each row with a correct value (not really a good option in my mind)

Upvotes: 2

Related Questions