Rerun all db migrations on Heroku (rake db:migrate:reset)
heroku, ruby-on-rails, ruby-on-rails-4
Solution
You should not make changes in your migration files which have already been migrated. If you look at `docs` it says
`In general, editing existing migrations is not a good idea. You will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead, you should write a new migration that performs the changes you require`
You should create a new migration file by
rails g migration AddColumnNameToUsers column_name:type
This will generate a migration file like:
class AddColumnNameToUsers < ActiveRecord::Migration
def change
add_column :users, :column_name, :type
end
end
And then you can simply run heroku run rake db:migrate
If you still want to Drop your database from heroku then you need to do:
heroku pg:reset DATABASE_URL --confirm nameofapp
and then heroku run rake db:migrate. For details checkout heroku docs
Problem
While developing a heroku app, before launch, I have been keeping my migrations into 2 files (Create Users, Create Posts) instead of adding a new migration everytime I change the structure of the tables (probably would be 20 iterations at this point). There is no data in the db yet. How can I do `rake db:migrate:reset`'s equivalent on Heroku? Heroku does not allow this. I was thinking I could do `heroku pg:reset` and then `rake db:migrate`, but this doesn't seem to rerun old migrations. Again, there is no data in Heroku's database, so it can be dropped. migrations: - 2014070781234_create_users_table I added a column in this migration. It has already been run on heroku. How can I rerun it so the table is updated? - 2014070789999_create_posts_table