1

This is not a duplicate of: Rails migration complains about undefined method `attachment' using paperclip

So we used paperclip and have now switched to activestorage but some of our old migrations are using add_attachment from paperclip which is making rails complain with this error message because we don't have paperclip in the gemfile anymore:

undefined method 'add_attachment' for #<AddAvatarColumnsToUsers:0x00007fafa90de890>

Should I have to keep paperclip installed or should i remove touch the migration? What is the proper way to deal with this issue? Any help would be great!!

Eyeslandic
  • 14,553
  • 13
  • 41
  • 54
isethi
  • 661
  • 1
  • 10
  • 22

2 Answers2

1

paperclip add_attachment creates four fields for each attachment, so to fix that, you can remove the paperclip gem, remove the old migration, and create a new one removing the fields added by add_attachment

"add_attachment :users, :photo" creates four fields in the users table photo_file_name photo_content_type photo_file_size photo_uploaded_at

after removing the old migration that uses remove_attachment, you can create a new one with:

remove_column :users, :photo_file_name remove_column :users, :photo_content_type remove_column :users, :photo_file_size remove_column :users, :photo_file_name

x0rist
  • 625
  • 4
  • 9
0

Old migrations are usually not necessary as long as they are part of the schema and have been deployed to all production instances and the database schema is stable enough. You can safely delete them.

TheGeorgeous
  • 3,927
  • 2
  • 20
  • 33