【问题标题】:Django + postgreSQL : why migrating did work even though I hadn't given my db info?Django + postgreSQL:为什么即使我没有提供数据库信息,迁移也能奏效?
【发布时间】:2021-10-09 11:14:27
【问题描述】:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'test',
    }
}

这是我的 settings.py。 DATABASE 'test' 有密码,但我没有输入。

为了测试,我尝试迁移:

创建超级用户也确实有效。和 psql,

我认为 Django 无法连接到数据库,因为我没有输入“用户”、“密码”字段,但数据在我的数据库中。怎么可能?

【问题讨论】:

  • 数据库是否更新。可能是您没有指定正确的设置文件,在这种情况下它将与 sqlite 一起使用,从而在文件系统中构造一个 sqlite。
  • 不太确定,但你可以有一个.pgpass 文件。
  • 抱歉,出错了。我刚刚编辑了我的问题。

标签: django postgresql migrate


【解决方案1】:

固定 pg_hba.conf:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     md5
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

alter METHOD : trust to md5 并重新启动 postgres 后,它可以正常使用“USER”或“PASSWORD”字段。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-11
    • 1970-01-01
    • 2019-10-11
    • 2013-11-24
    • 2023-04-02
    • 2021-09-20
    • 2019-01-27
    • 1970-01-01
    相关资源
    最近更新 更多