Postgresql: FATAL: password authentication for user "douglas"

I am trying to migrate 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 always get the same error:

django.db.utils.OperationalError: FATAL: Password authentication failed for user "Douglas"

These are 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 "ALTER USER postgres WITH PASSWORD" I enter the same password that is specified in settings.py.

+12


source to share


4 answers


The SQL you are using does not match the user you are trying to use.

You need to create a user if it doesn't exist:

CREATE USER douglas WITH PASSWORD 'vamointer';

      



or, if it exists, change this user password .

ALTER USER douglas WITH PASSWORD 'vamointer';

      

Once you do this, you are more fortunate. You may also need to assign permissions to this user .

+11


source


Special characters in postgresql are converted to different characters at runtime. Make sure there are no special characters (#, $, etc.) in your password.

If you do, change the postgresql password as follows:



sudo -u postgresql psql
postgresql=#ALTER USER yourusername WITH PASSWORD 
'set_new_password_without_special_character';

      

Make sure you don't forget ;

at the end of the postgresql command. Then run python manage.py

it and it should work!

+4


source


If you are as dumb as me and used "USERNAME" instead of "USER" in your Django database configurations in settings.py, make sure you change it to "USER", otherwise you will see the same error. Hope this helps someone like me in the future.

+1


source


You can try this:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'NAME': 'telusko',
    'USER': 'postgres', #in place we should always be write USER only if we write USENAME then it will give error.
    'PASSWORD': '1234',
    'HOST':'localhost',
}}

      

0


source







All Articles