0

I have created a new migration in order to add a new Paperclip attachment to a current model already owning a Paperclip attachment.

Though made an error and defined the data type as attachment instead of add_attachment :

class AddDetailsToProfilepics < ActiveRecord::Migration[5.0]
  def change
    add_column :profilepics, :finalimage, :attachment
  end
end

Then i noticed no extra column was created by paperclip (*_file_name *_content_type) and realise I made a mistake.

Though now no Rollback is possible as it triggers an error. I created a new migration (to remove this column with wrong data type) and got a similar error:

undefined method 'to_sym' for nil:NilClass

When looking at shema.rb the data type is not entered:

        ...
        t.integer  "y"
        t.integer  "width"
        t.integer  "height"
        t.         "finalimage"
        t.index ["professionnel_id"], name: "index_profilepics_on_professionnel_id"

I tried to change it to string and re-run the new "remove_column" migration but same error.

Maxence
  • 2,029
  • 4
  • 18
  • 37
  • When you say you tried to change it, did you change it in the schema file and then try, or did you create a migration just to change that one column's data type like => http://stackoverflow.com/questions/2799774/rails-migration-for-change-column? – Rockwell Rice Dec 29 '16 at 16:14
  • So you are saying no extra column has been created means the database has no extra column added through this migration? – Deepesh Dec 29 '16 at 16:15
  • I try to add a random data type directly in the shema file. Should I try to migrate it into another datatype ? No migration involving this field seem to work .. – Maxence Dec 29 '16 at 16:16
  • I don't see the 'papeclip' columns that are usual when adding an attachment. Actually in my database, the finalimage field appear as TEXT. (but it does appear indeed, a field has been created but a normal field) – Maxence Dec 29 '16 at 16:17

1 Answers1

0

Ok I found solution. Kill both development.sqlite3 and schema.rb. Delete reference to the wrong column in the last migration. Do a rails db:migrate Everything will be reconstructed. The DB is empty though

Maxence
  • 2,029
  • 4
  • 18
  • 37