简体   繁体   中英

How to connect with postgresql database after deployment to Heroku?

I'm new to Django but I'm deploying a Django-based website to Heroku, using Postgresql. The deployment was successful, and the website is online and has established connection with the database. However, none of the data from my local database has migrated to the heroku database, causing it to be a blank database. If I go into the admin section and manually input a datapoint, it appears on my site, so I know that database is correctly serving data. What is the proper way for migrating data from your local database to your online, heroku version of the database? I thought the following code would migrate the data:

heroku run python manage.py makemigrations
heroku run python manage.py migrate

But apparently I'm missing something.

make migrations will create a migration that contains your schema, but no data. The migrate command applies the migration to the database.

In order to provide data to be sent over as part of the migrate command you need to either create a data migration or use a fixture .

Another option you have is to dump your local database and do an import into Heroku Postgres

All in all, it depends on how much local data you have that you want copied over. If its only a few rows, I would use either a data migration or a fixture, if its 100s or 1000s of rows an export/import of your dataset is your best bet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM