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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With