Trying to reset database on Heroku

Hi there,

I’m currently trying to reset the remote database so that I can run a migration that is failing with this message:

• Added the required column `foo` to the `bar` table without a default value. There are Some(2) rows in this table, it is not possible.

I tried finding a guide and saw this: How to reset PG Database on Heroku (for Rails app)? · GitHub, but there is no rakefile so this method wouldn’t work. Is there a way to do this?

Thanks!
Angelo

Hi aspampinato :wave:!

Rakefiles are used with Ruby – but you do not need to reset a database with a Rakefile and in fact that gist is not suggesting to do that – the rake task there is to run a Rails migration.

There are two ways to reset your Postgres database on Heroku

  1. Command line via the Heroku CLI

heroku pg:reset DATABASE

  1. Via the Heroku Dashboard for your app or all your datastores

Note: It might be wise to backup the database before reseting – again either via the CLI or Admin UI.

If you do not have the Heroku CLI, you can install it.

Note: obviously this is a destructive task, so again – if you need the data, please backup.

If you need to clean out you database but do not want to “reset”, the other way would be to use TablePlus to truncate all your tables (with cascade) and then delete them (including the _Migrations) and make sure you restart identities. I often do this in my dev environment and you can write a SQL script to do that repeatedly if needed.

1 Like

From the Heroku Dashboard, I’ve done a hard reset so. many. times. ¯_(ツ)_/¯

So +1 to the Heroku CLI option from @dthyresson

And also +1 to TablePlus — probably the best choice+tool for this in general.

Thanks for the reply! After you do the reset command, how do you re-run the migrations? After running the reset command it looks like this isn’t happening automatically.

+1 for TablePlus

After you do the reset command, how do you re-run the migrations?

By running yarn rw db up