I created a migration:
class AddFormCounterToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :form_count, :integer, default: 0
end
end
I ran rails db:migrate
but soon realised I had renamed the column incorrectly. So I ran git reset master --hard
-- so that the migration file was removed and schema.rb
was reset -- and started again:
class AddFormCounterToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :forms_count, :integer, default: 0
end
end
But when I ran rails db:migrate
this time, not only was the new column created but also the old one.
t.integer "form_count", default: 0
t.integer "forms_count", default: 0
Wuh? So I ran rails db:rollback
to see if that would work. But that fails with the error: No migration with version number 20181025092233.
Since I hadn't committed that file, I believe there isn't a way of restoring it.
Where and why is this migration persisting? What's the best practise when deciding to remove and redo a migration? What's the best way out of this pickle? Is there any way other than running rails db:reset
? (I'm using Postgres.)