我有一个名为postgres的数据库,但是当尝试连接时,它会给出以下错误输出:端口5432失败:致命:数据库“postgres”不存在。如果我改变到template 1它的工作,但我想使用postgres。
数据库列表:
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
-----------+----------+----------+-------------+-------------+------------+-----------------+-----------------------
postgres | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | | libc |
template0 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
Django settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'db',
'PORT': 5432,
}
}
请注意,我使用的是Docker. docker-compose.yml
version: "3.9"
services:
db:
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
volumes:
postgres_data:
1条答案
按热度按时间mpgws1up1#
从数据库中删除此端口。
看看能不能解决。
如果它不能解决,那么请确保您在构建Dockerfile时安装了psycopg2。