skip to Main Content

I am trying to switch my Django database from SQLite3 to PostgreSQl, so I follow many tutorials to install and setup Postgres with Django project.

I did the following: pip install psycopg2, pip install psycopg2-binary and I modified the settings.py like that:

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.postgresql',

        'NAME': BASE_DIR / 'db.postgresql',

        'USER': 'muusername',

        'PASSWORD': 'mypassword',

        'HOST': '127.0.0.1',

        'PORT': '5432'

    }

}

Finally I maked my database, by running the command python manage.py makemigrations.
However, I got this error:

django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgresql' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:
    'mysql', 'oracle', 'sqlite3'

Please note that I am also seccesufully install the pgAdmin in my OS which is Windows 10 in a first step.

I know that the problem is related by configuration of Postgres in my django project, but I don’t know how to fix it, also I checked my djnago version which is the latest one, also, all needed packages are installed in my venv.

3

Answers


  1. Chosen as BEST ANSWER

    I solve this problem by just upgrade the django, as you can see here in the exception:

    django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgresql' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:
    'mysql', 'oracle', 'sqlite3'
    

    Django ask the user to use mysql, oracle or sqlite3, but not the case of postgresql. So this exception will be fixed when the user upgrade the django version.

    I hope this answer can be helpful for someone another.


  2. You cannot add like this in postgres:

    'NAME': BASE_DIR / 'db.postgresql', #You got that error because of this. This setting is for only sqlite3 not for postgres
    

    Just add db_name in NAME:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'your_db_name', #add your db name here
            'USER': 'postgres',
            'PASSWORD': 'your_db_password',
            'HOST': '127.0.0.1', 
            'PORT': '5432',
        }
    }
    
    Login or Signup to reply.
  3. Make sure you have actually downloaded the PostgreSQL installer itself and installed it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search