Using PostgreSQL with Django
Here is how go set up Django to work with PostgreSQL
- Install necessary libraries, etc
- sudo apt-get install libpq-dev
- sudo apt-get install python-dev
- sudo apt-get install postgresql-contrib
- Create a new database and user
- sudo su – postgres
- createdb djangodev
- createuser -P djangodev
- Enter password, twice
- psql
- postgres=# GRANT ALL PRIVILEGES ON DATABASE djangodev TO djangodev;
- \q
- Make sure you have your virtual environment activated
- pip install psycopg2
- Open up the project’s settings.py and change the DATABASES to:
DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.postgresql_psycopg2’, # Add ‘postgresql_psycopg2’, ‘mysql’, ‘sqlite3’ or ‘oracle’.
‘NAME’: ‘djangodev’, # Or path to database file if using sqlite3.
‘USER’: ‘djangodev’,
‘PASSWORD’: ‘… PASSWORD …’,
‘HOST’: ‘localhost’, # Empty for localhost through domain sockets or ‘127.0.0.1’ for localhost through TCP.
‘PORT’: ”, # Set to empty string for default.
}
} - python manage.py syncdb