简体   繁体   中英

How to push local django database into heroku database

I have created django project with postgres database I have deployed my project into heroku server, and also migrate with

heroku run python manage.py migrate

I want to push my stored database to heroku database,

PGUSER=edpuser PASSWORD=1qazxsw2 heroku pg:push applications postgresql-curly-07168 --app application

but getting

> error   shiv@shiv:~/Documents/projects/django_related_project/zoedp$
> heroku pg:push applications postgresql-curly-07168 --app application
> heroku-cli: Pushing applications ---> postgresql-curly-07168  ▸   
> Remote database is not empty. Please create a new database or use
> heroku pg:reset

I also run command heroku pg:reset and again try again this time I got error

shiv@shiv:~/Documents/projects/django_related_project/zoedp$ PGUSER=edpuser PASSWORD=1qazxsw2 heroku pg:push applications postgresql-curly-07168 --app application
heroku-cli: Pushing edpapplication ---> postgresql-curly-07168
pg_dump: [archiver (db)] connection to database "application" failed: FATAL:  Peer authentication failed for user "edpuser"
pg_restore: [custom archiver] could not read from input file: end of file
 ▸    pg_dump errored with 1

here is my setting.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'applications',
        'USER': 'edpuser',
        'PASSWORD': '1qazxsw2',
        'HOST': 'localhost',
        'PORT': '5432',
        'ATOMIC_REQUESTS': True
    }
}

import dj_database_url

db_from_env = dj_database_url.config(conn_max_age=600)
DATABASES['default'].update(db_from_env)

and overwriting pg_hba.conf deny me. what should I do?

I was having this issue, is more related to postgresql auth configuration rather than heroku pg:push command

I would recommend this approach:

Set a password for the postgres user: Based on this amazing answer: https://stackoverflow.com/a/26735105/3172310

At this moment: You have set a password for the postgres user and configure postgres to ask for id when using psql, which seems pg command does.

then run command as this:

PGUSER=postgres PASSWORD=pg_password heroku pg:push local_db_name DATABASE_URL --app application_name

Replacing:

  • pg_password: password for the postgres user
  • local_db_name: your local database
  • application_name: heroku app name

and should work fine!

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