[英]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:解决方案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.