Django With POSTGRESQL in Ubuntu


The first step is to change the database engine in the application’s settings.py file:
'ENGINE': 'django.db.backends.postgresql_psycopg2'
Running python manage.py syncdb returned the following error:
Error loading psycopg module: No module named psycopg
I’ve tried installing the psycopg2 package, but that resulted in another error:
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application
The libpq-dev package had to be installed to meet all the dependencies:
sudo apt-get install libpq-dev
sudo pip install psycopg2
But still, the syncdb command wasn’t returning the desired result:
Peer authentication failed for user "someuser"
I needed to open up the file /etc/postgresql/9.1/main/pg_hba.conf in a text editor (with root privileges) and change this line:
local   all             all                                     peer
to this:
local   all             all                                     md5
I had to restart the PostgreSQL server to load the new settings:
sudo service postgresql restart
Now Django should have a proper connection with the PostgreSQL database.

Comments

Popular posts from this blog

Run tasks in background in Spring

Conditional field inclusion in Jackson and Spring Boot

How to configure Wildfly 10 to use MySQL