6

I am trying to migrate an app from Django 1.8 and Python 2 to Python 3.6 and Django 3.0.

Whenever I am adding django.db.backends.postgresql_psycopg2, and installing it via pip3 I am getting this error:

_psycopg2 module not found.

I looked at the documentation, and I see that in Django 3.0 _psycopg2 is removed. How can I resolve this issue? My previous app is running psycopg 2.6.1.

Mihai Chelaru
  • 7,614
  • 14
  • 45
  • 51
  • 1
    Incompatible chances between Django releases are well documented, as well as [the whole migration process](https://docs.djangoproject.com/en/3.0/howto/upgrade-version/) – bruno desthuilliers Dec 18 '19 at 16:23

1 Answers1

13

The correct setting to use in Django 3.0 is 'django.db.backends.postgresql'.

From the Django deprecation timeline:

The django.db.backends.postgresql_psycopg2 module will be removed.

This particular module has actually been deprecated since Django 2.0:

The django.db.backends.postgresql_psycopg2 module is deprecated in favor of django.db.backends.postgresql. It’s been an alias since Django 1.9. This only affects code that imports from the module directly. The DATABASES setting can still use 'django.db.backends.postgresql_psycopg2', though you can simplify that by using the 'django.db.backends.postgresql' name added in Django 1.9.

From the databases docs, it looks like your version of psycopg2 should be supported, as you need 2.5.4 or higher.

Mihai Chelaru
  • 7,614
  • 14
  • 45
  • 51
  • Yeh I did that, And I installed Postgres. but when I run my app I get django.db.utils.OperationalError Could not connect to server on port 5432 . this is first time am creating an app. and I still couldn't run it. –  Dec 18 '19 at 16:28
  • That sounds like a completely distinct problem from the question you posted. You should include all information in your question so that it's clear what your actual problem is. Have you looked at [this post](https://stackoverflow.com/q/29937378/9374673) with respect to not being able to connect to Postgres from Django? – Mihai Chelaru Dec 18 '19 at 16:34
  • I checked that one, and it didn't help. I am trying the command they given service postgresql status it keeps giving me Postgres.service no found –  Dec 18 '19 at 16:41
  • 1
    I'm really not sure how to solve that issue, but I'm sure this has been asked before, such as [here](https://stackoverflow.com/q/41867841/9374673). See what else you can try, and if that doesn't resolve it, post a new question with the information you gave me here, ideally a full traceback of the error you're getting and what you've tried so far, and hopefully someone will be able to solve your problem. I did my best to answer your question here based on the information you provided, but it seems you have issues with Postgres itself, which has nothing to do with Django. – Mihai Chelaru Dec 18 '19 at 16:44