When trying to add attachment "image" to model "product" using gem CarrierWave, I used the following steps:

  1. Created a new column with rails g migration AddImageToProduct

  2. rake db:migrate

  3. Added :image in product_params in the private section of products_controller.rb

However, I found out that even after repeated db:migrate / db:reset commands, I still could not get the uploader working. I then realized that in the schema.rb file that the "image" had not been added as a column, so the migration had failed.

The fix was to run the following commands:

rake db:drop
rake db:create
rake db:migrate
rake db:seed

(The db:seedcommand is optional as I had manipulated the seed.rb file to create an admin account and normal account everytime the database is recreated.)

This fixed the database issue and now the schema.rb file has the "image" column added, and I could upload images successfully. Apparently when running db:reset, even though the system drops and recreates the database, it takes the old schema document rather than re-running all the migration files to update the schema.