如何将本地Django数据库推入heroku数据库

2024-04-29 17:22:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经用postgres数据库创建了django项目,我已经将我的项目部署到heroku服务器中,并且还使用

heroku run python manage.py migrate

我想将存储的数据库推送到heroku数据库

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

但是

> 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

我还运行命令heroku pg:reset并重试 这次我犯了个错误

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

这是我的设置。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)

覆盖pg_hba.conf拒绝我。 我该怎么办


Tags: django数据库appdbherokuapplicationpostgresqlpassword
1条回答
网友
1楼 · 发布于 2024-04-29 17:22:49

我遇到了这个问题,它与postgresql auth配置有关,而与herokupg:push命令无关

我建议采取这种做法:

postgres用户设置密码: 基于这个惊人的答案:https://stackoverflow.com/a/26735105/3172310

此时此刻: 您已经为postgres用户设置了密码,并将postgres配置为在使用psql时请求id,这似乎是pg命令所做的

然后按如下方式运行命令:

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

替换:

  • pg_密码:postgres用户的密码
  • 本地数据库名称:您的本地数据库
  • 应用程序名称:heroku应用程序名称

而且应该很好

相关问题 更多 >