I am trying to migrate a DB from sqlite to postgresql...so I typed:
sudo -u postgres psql postgres=# ALTER USER postgres WITH PASSWORD 'newpassword';
and the output returns ALTER ROLE
but when I type python manage.py migrate
I receive always the same error:
django.db.utils.OperationalError: FATAL: password authentication failed for user "douglas"
This is the database sections of my settings.py.
# Old, using mysqlite """ DATABASES = { #'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), #} 'default': dj_database_url.config(default='postgres://localhost:5432/postgres_db_name'), } """ # New, using postgres DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'douglas_db', 'USER': 'douglas', 'PASSWORD': 'vamointer', 'HOST': '127.0.0.1', 'PORT': '5432', } }
Note: When I run the 'ALTER USER postgres WITH PASSWORD' I put in the same password defined in the settings.py.
Restart the PostgreSQL service from the Services control panel ( start->run->services. msc ) Connect using psql or pgAdmin4 or whatever you prefer. Run ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'
Step 1: Log in to the server using the SQL Shell (psql) app. Step 2: Run the following query: SELECT datname FROM pg_database; psql runs the query against the server and displays a list of existing databases in the output.
The SQL you are running does not match the user you are attempting to use.
You will need to create the user if it does not exist:
CREATE USER douglas WITH PASSWORD 'vamointer';
or if it does exist, change that user's password instead.
ALTER USER douglas WITH PASSWORD 'vamointer';
Once you have done that you should have more luck. You may need to assign permissions to that user as well.
If you are bone-headed like me and have used 'USERNAME' instead of 'USER' in your Django database configs in settings.py, make sure you change it to 'USER' else you will see this same error. Hope this helps someone like me down the road.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With