Install Postgres:
$ sudo apt-get install postgresqlThis installs version 9.1 on my system. It automatically creates a user called postgres.
Set the password:
$ sudo passwd postgresand enter a password twice.
Switch user:
$ su postgresCreate a user named django_login:
$ createuser -P django_loginand enter a password twice. This is the password you will be using in your settings.py file. Enter the Postgres shell:
$ psql template1Create a database:
CREATE DATABASE django_db OWNER django_login ENCODING 'UTF8';Get out of the db shell by typing:
$ \qEdit the Postgres permissions in /etc/postgresql/9.1/main/pg_hba.conf by adding a line as follows after the postgres user line:
local django_db django_login md5Restart Postgres:
$ sudo /etc/init.d/postgresql restartDownload python-psycopg2 which lets Postgres talk to Python:
$ sudo apt-get install python-psycopg2Edit your settings.py file in the django app directory:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_db',
'USER': 'django_login',
'PASSWORD': 'your_password',
'HOST': 'localhost',
'PORT': '5432',
}
}
Make sure that this is the correct port by running:$ grep postgresql /etc/servicesSync your db while in your django project directory:
$ python manage.py syncdbIf this works, you are now using Postgres with Django!
References: http://blog.iiilx.com/programming/how-to-install-postgres-on-ubuntu-for-django
this is some good stuff
ReplyDeleteThanks for sharing. I got it!
ReplyDelete