Search code examples
ruby-on-railspapercliprails-activestorage

Rails migrations complains about "add_attachment"


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!!


Solution

  • 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