Home > Enterprise >  Deploy Django app to Heroku AFTER DATABASE?
Deploy Django app to Heroku AFTER DATABASE?

Time:10-15

I have deployed my django website to Heroku but since the website fields are dependent upon a database that is on my local machine. I've tried using Postgres but the database on Heroku doesn't populate with the data I need it to before the app runs. Has anyone experienced this? Do I need to use an exteranl database on AWS or something (in which case, what is the best way to do this?)

CodePudding user response:

Use load data and dump data: https://docs.djangoproject.com/en/3.2/ref/django-admin/#loaddata

First dump the data on your local machine

python manage.py dumpdata ..other_options > data.json

add it to git and push to herkou

git add data.json
git commit -m "Added data"
git push heroku master

now on Heroku can use loaddata to load your data to database

heroku run python manage.py loaddata data.json

And your done.

CodePudding user response:

I have deployed a Django project on Heroku where I had data in models even after the deployment the data remained in the models. I worked on SQLite in production. Heroku works with Postgres but on deploying also my data remained safe. I just used git push heroku main

  • Related