简体   繁体   中英

Django psycopg2.OperationalError: fe_sendauth error but not connecting to postgresql database

I am using the following sqlite connection in my myapp/settings.py file:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': ':testdb:',
        #I also tried 'NAME': 'testdb',
    },
}

in my manage.py file I am using:

if __name__ == "__main__":
    os.environ.setdefault("myapp.settings")
    from django.core.management import execute_from_command_line
    execute_from_command_line(sys.argv)

On running ./manage.py migrate on the command line I get the following error:

django.db.utils.OperationalError: fe_sendauth: no password supplied

I tried removing psycopg2 and re-ran the migration and get the following error:

django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'

I can't work out why django is trying to connect to a psql database where the only DATABSES configuration in the application is for sqlite3.

Could this be due to a dependency?

Try this,

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

This might be helpful for you.

Django only uses DATABASES setting to generate migrations using a specific database driver. I believe somewhere, there is an import which is overriding your DATABASES setting. These are possible places to look for debugging in order of priority.

  1. Any import into settings.py file after you set DATABASES variable which might override it.
  2. if above is not the case, Some dependency must be overriding this setting manually. you might want to look into your INSTALLED_APPS .
  3. If still not enough, you might need to look at any other dependency that you are using in your project which tries to interact with django.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM