Data Migration in Active Storage after changing the Model name

twitter logo github logo ・1 min read

πŸ€” What does it mean about 'run a migration'

According to Rails Guide, it says

Alt Text

β˜•οΈ My Situation

I changed my model name

  • From: Media
  • To: Medium


All of the objects had not had any attachment.

🧐 WHY?

ActiveStrage is the polymorphic model. So, the records were still looking at the old model. Then, the association is cut.

πŸ”§Treatment from Rails Console

ActiveStorage::Attachment.where(record_type: "Media").update(record_type: "Medium")
twitter logo DISCUSS
Classic DEV Post from Aug 23 '18

The Rails Ecosystem is Healthier than Ever

This is the first post in a new "flare tag" we're trying out: #healthydebate. ...

n350071 profile image
Ruby Web Developer. Freelancer.

πŸ‘‹ Hey dev.to reader.

Do you prefer sans serif over serif?

You can change your font preferences in the "misc" section of your settings. ❀️