Question

I have a db with columns (name, path). Now I have a migration file that changes the columns to be (name, pathorig, pathjson, scramble).

Doing rake db:reset and rake db:migrate doesn't update the table. Why can this happen?

my migration file:

class CreateUploads < ActiveRecord::Migration
  def change
    create_table :uploads do |t|
      t.string :name
      t.string :pathorig
      t.string :pathjson
      t.string :scramble

      t.timestamps
    end
  end
end

The schema.rb file:

ActiveRecord::Schema.define(version: 20131029072745) do

  create_table "uploads", force: true do |t|
    t.string   "name"
    t.string   "path"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

end
Was it helpful?

Solution

Difference between rake db:migrate db:reset and db:schema:load has a great explanation of what the various rake db:* commands do.

Because rake db:reset performs a db:schema:load, it's loading the old columns from your table, rather than calling db:migrate, this is why your migration isn't being run.

Consider writing a migration that changes the names of those columns, rather than re-creates an existing table, or manually run rake db:drop; rake db:create db:migrate

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top