简体   繁体   English

将 Django 连接到 Postgres:django.db.utils.OperationalError:致命:数据库“DATABASENAME”不存在

[英]Connecting Django to Postgres: django.db.utils.OperationalError: FATAL: database "DATABASENAME" does not exist

I have just started learning Django after I took some tutorials for Python.在我学习了一些 Python 教程后,我才刚刚开始学习 Django。

I am trying to connect my POSTGRES database to the Django project I have just created.我正在尝试将我的 POSTGRES 数据库连接到我刚刚创建的 Django 项目。

However, I am experiencing this problem:但是,我遇到了这个问题:

django.db.utils.OperationalError: FATAL:  database "producthuntdb" does not exist

I followed these steps:我按照以下步骤操作:

1) Opened postgress by clicking its icon 1) 通过单击其图标打开 postgress

2) Clicked on the database "postgress". 2)点击数据库“postgress”。 The terminal opened and I wrote: CREATE DATABASE producthuntdb ;终端打开,我写道: CREATE DATABASE producthuntdb ; The database has been created because I see it if I open postgress via its icon.数据库已经创建,因为如果我通过它的图标打开 postgress,我就会看到它。

3) Went to my Django project in "settings" and change the SQLITE database to the following: 3)在“设置”中进入我的Django项目并将SQLITE数据库更改为以下内容:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'producthuntdb',
        'USER': 'mymac2017',
        'PASSWORD': 'mypassword',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

4) Run the code python3 manage.py migrate 4)运行代码python3 manage.py migrate

However, I am getting the error:但是,我收到错误:

django.db.utils.OperationalError: FATAL: database "producthuntdb" does not exist

So I did the following:所以我做了以下事情:

  • Cliking on postgress icon and opening the the database producthuntdb单击 postgress 图标并打开数据库producthuntdb

  • Once the terminal is open, I wrote: \\du终端打开后,我写道: \\du

  • There are two users with the attributes:有两个用户具有以下属性:

    1) mymac2017 | 1) mymac2017 | Superuser, Create role, Create DB |超级用户、创建角色、创建数据库 | {} {}

    2) postgres | 2)postgres | Superuser, Create role, Create DB, Replication, Bypass RLS |超级用户、创建角色、创建数据库、复制、绕过 RLS | {} {}

What am I doing wrong?我究竟做错了什么?

I tried to look other answers to this problem and most of the issues are from misspelling the database name OR not creating it.我试图寻找这个问题的其他答案,大多数问题来自拼错数据库名称或没有创建它。 However, the name of my database is correct and I can see the database producthuntdb if I open postgres.但是,我的数据库名称是正确的,如果我打开 postgres,我可以看到数据库producthuntdb

Many thanks for your help.非常感谢您的帮助。

I set the wrong port of the Database in the Django "settings.py".我在 Django“settings.py”中设置了错误的数据库端口。

I was using 'PORT': '5432' instead of 'PORT': '5433'我使用'PORT': '5432''PORT': '5432'而不是'PORT': '5433'

SOLUTION:解决方案:

  • Go to your Postgres app/icon/program转到您的 Postgres 应用程序/图标/程序
  • Click on "Server setting" and see which PORT the database POSTGRES is using单击“服务器设置”并查看数据库 POSTGRES 使用的端口
  • Be sure that the PORT the database is using is the same as the one you write in the "settings.py" of your Django project.确保数据库使用的端口与您在 Django 项目的“settings.py”中编写的端口相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 django.db.utils.OperationalError:致命:数据库“ clinilead_e”不存在 - django.db.utils.OperationalError: FATAL: database “clinilead_e ” does not exist 将 Django 连接到 Docker Postgres 实例引发 django.db.utils.OperationalError - Connecting Django to Docker Postgres instance raising django.db.utils.OperationalError django.db.utils.OperationalError:致命:用户“postgres”的密码认证失败 - django.db.utils.OperationalError: FATAL: password authentication failed for user "postgres" 姜戈; django.db.utils.OperationalError: 致命: 没有主机、用户、数据库的 pg_hba.conf 条目 - Django; django.db.utils.OperationalError: FATAL: no pg_hba.conf entry for host, user, database django.db.utils.OperationalError: 没有这样的表 Django 2 - django.db.utils.OperationalError: no such table Django 2 Django:django.db.utils.OperationalError: 没有这样的列 - Django:django.db.utils.OperationalError: no such column django.db.utils.OperationalError:(1046,'没有选择数据库') - django.db.utils.OperationalError: (1046, 'No database selected') django.db.utils.OperationalError:SQLite3 数据库中没有这样的表 - django.db.utils.OperationalError: no such table in SQLite3 database 迁移错误(django.db.utils.OperationalError) - Migration error(django.db.utils.OperationalError) django.db.utils.OperationalError: 没有这样的表 - django.db.utils.OperationalError: no such table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM