Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to completely reset Postgres database on Heroku?

I have a learning project deployed on Heroku. It had a Postgres database provisioned. I introduced some major changes in the models of my Django project and destroyed the old database and provisioned a new one, which is totally empty, but it is not working like an empty database.

When I run the command heroku run python manage.py makemigrations, I get the error message

You are trying to add a non-nullable field....

Why am I getting this message when I have destroyed the old database?

like image 613
Kaptan Singh Avatar asked Jan 27 '23 02:01

Kaptan Singh


1 Answers

First of all, you should never run manage.py makemigrations on Heroku.

By the time your code gets there no model changes should exist to generate new migrations. Run makemigrations locally to create migration files. Run migrate locally and on Heroku to apply migrations to your database.

Now that that's out of the way, this is likely caused by existing migrations files, not anything in your database. If you truly want to start over you can delete the files from each of yours apps' migrations/ directories.

Finally, there is no need to destroy and reprovision your database to reset it. Instead you can use heroku pg:reset:

The PostgreSQL user your database is assigned doesn’t have permission to create or drop databases. To drop and recreate your database use pg:reset.

like image 78
Chris Avatar answered Jan 29 '23 08:01

Chris