Hello everyone, I’m a Django beginner. I’m trying to migrate data from an SQLite database to a PostgreSQL database, but I’m encountering such an error during the process.
django.db.utils.OperationalError: connection failed: password authentication failed for user "blog"
Multiple connection attempts failed. All failures were:
- host: 'localhost', port: '5432', hostaddr: '::1': connection failed: password authentication failed for user "blog"
- host: 'localhost', port: '5432', hostaddr: '127.0.0.1': connection failed: password authentication failed for user "blog"
I created the database using Docker containers. Here are the commands I used:
docker run --name=blog_db -e POSTGRES_DB=blog POSTGRES_USER=blog -e POSTGRES_PASSWORD=A0116659 -p 5432:5432 -d postgres:16.2
I also created an environment configuration file in the root directory of my project
In which I stored the database environment configuration parameters.
DB_NAME=blog
DB_USER=blog
DB_PASSWORD=A0116659
DB_HOST=localhost
DB_PORT=5432
Finally, in the main project’s settings.py file, I modified the default SQLite database configuration.
from decouple import config
#配置新型的数据库
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": config("DB_NAME"),
"USER":config("DB_USER"),
"PASSWORD":config("DB_PASSWORD"),
"HOST":config("DB_HOST"),
"PORT":config("DB_PORT",default=5432)
}
}
Finally, when I ran python manage.py migrate
, an error occurred.
django.db.utils.OperationalError: connection failed: password authentication failed for user "blog"
Multiple connection attempts failed. All failures were:
- host: 'localhost', port: '5432', hostaddr: '::1': connection failed: password authentication failed for user "blog"
- host: 'localhost', port: '5432', hostaddr: '127.0.0.1': connection failed: password authentication failed for user "blog"
I don’t know why the password verification is failing. I’m sure I entered the correct password, but it still gives an error. I hope everyone can help me. Your suggestions will be greatly appreciated!