I deployed my app using Heroku, but while deploying Heroku created a new PostgreSQL database. Now I need to change that to my already existing PostgreSQL database(I am using Django framework in VsCode), which I used while running in the localhost. Does anyone have an idea, please help me with this?.
1 Answer
I would create a database dump and import it into your Heroku Postgres.
Use pg_dumpto create a dump and then upload it to heroku.
A detailed description can be found on the heroku dev center
Additionally, there is a quite good Stackoverflow entry on this topic here
According to this follow these steps and you should be fine.
Create a dump from the source PostgreSQL database
$ PGPASSWORD=YOUR_PG_PASSWORD pg_dump -Fc --no-acl --no-owner -h localhost -U YOUR_PG_USER YOUR_DB_NAME > YOUR_DB_NAME.dump
Get the Heroku Postgres credentials for your heroku app
$ heroku pg:credentials:url -a YOUR_APP_NAME
Attempt to import PostgreSQL dump to Heroku using the credentials above
$ pg_restore --verbose --clean --no-acl --no-owner -h HOSTNAME -U USER -d DATABASE -p PORT PATH/TO/YOUR_DB_NAME.dump --password
Enter the password received from the Heroku Postgres credentials It should then import the dump successfully