Home > Blockchain >  How do I recommit database to Heroku after destroying DB in the Heroku dashboard
How do I recommit database to Heroku after destroying DB in the Heroku dashboard

Time:03-20

I've built an app using Django etc. I ran into a whole bunch of problems with database on Heroku after accidentally pushing to production before running heroku run python manage.py makemigrations and heroku run python manage.py migrate.

I decided to just completely destroy the database currently on Heroku and want to recommit my app's models to heroku. My hope is to completely start from a clean slate.

I just want to make sure I do this correctly so I'm asking for clear instructions about how to recommit my app's database to Heroku after destroying the database in the dashboard.

Current error I get when I open my app online is:

settings.DATABASES is improperly configured. Please supply the NAME or OPTIONS['service'] value.

Thanks!

CodePudding user response:

If you completely removed your database you'll have to provision another one. Assuming you are using Heroku Postgres¹, you can do that using the Heroku CLI like so:

heroku addons:create heroku-postgresql:hobby-dev

Here we are asking Heroku to provision the heroku-postgresql add-on using the free hobby-dev tier. Modify as needed.

You can also provision add-ons using the Dashboard if you prefer.

As part of the provisioning process, Heroku Postgres will automatically set a new DATABASE_URL for your app. As long as your project was using this variable before you deleted your old database, it should find the new database without requiring any changes.


¹If you were using a different database add-on the solution should be more or less the same. Provision a new instance of the add-on, let it set its environment variable, and if your app was using that variable before it should pick it up on its own.

  • Related