DEV Community

n350071🇯🇵
n350071🇯🇵

Posted on

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)