0

I'm finishing a major refactoring of an app and I am trying to clean up the migrations. I've made the changes and everything works great locally after reseting and re-migrating the database.

On production I can't get the migrations to run. I've tried every combination of reset, drop, etc. that I can think of but I keep getting this error.

It seems like the production database isn't being reset which is causing the migration to break. Any tips would be appreciated.

==  AddFieldsToUsers: migrating ===============================================
-- add_column(:users, :company, :string)
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: company: ALTER TABLE "users" ADD "company" varchar(255)
Eric
  • 429
  • 2
  • 6
  • 15
  • 3
    If you need to "recreate" your DB you mustn't use migrations. Use the `rake db:schema:load` task for this. – jdoe Jan 30 '13 at 21:28
  • @jdoe I encourage everyone who gives awesome answers to write them as answers so they can be accepted and upvoted! :-) – Dennis Hackethal Jan 31 '13 at 01:03

1 Answers1

1

For resetting the database you can drop and migrate the database again in production mode.

rake db:drop db:create db:migrate RAILS_ENV=production

And, if you want to edit some particular migration, you can reset it using its version no.

rake db:migrate:down VERSION=<version no.> RAILS_ENV=production

Edit the migration file, and then

rake db:migrate:up VERSION=<version no.> RAILS_ENV=production
Aman Garg
  • 4,198
  • 2
  • 21
  • 29