DEV Community

n350071πŸ‡―πŸ‡΅
n350071πŸ‡―πŸ‡΅

Posted on

2 2

Data Migration in Active Storage after changing the Model name

πŸ€” 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

Then

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")
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free β†’

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay