Ubuntu14.04 系統下Django配置使用Postgresql數據庫配置

下面是簡略的配置,重點是Django配置Postgresql,由於Django使用pq須要psycopg2,重點是模塊psycopg2的依賴模塊!python

1、更新系統

sudo aptitude install update
sudo aptitude install upgrade

 

2、安裝pip安裝環境

sudo aptitude  install python-pip

 

3、安裝django

sudo pip install django==1.8

 

4、安裝Postgresql數據庫

sudo aptitude install postgresql-9.3

 

5、安裝psycopg2

1.安裝環境依賴sql

sudo aptitude install python-dev libpq-dev

 

2.安裝模塊數據庫

sudo pip install psycopg2

 

6、配置Postgresql

psql# create user abc with 'abc';   #新建用戶abc,密碼abc
psql# create database abc owner abc;   #新建數據庫及其屬主 abc

 

修改配置權限,不然沒法初始化PG(本文最後一步)django

sudo vim /etc/postgresql/9.3/main/pg_hba.conf

將85,90,92行行末的peer和MD5,修改成trust(信任)vim

保存退出post

7、配置Django

project_name:    aspa

修改配置文件  a/a/settings.pypostgresql

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME':'abc',          #數據庫名
        'USER': 'abc',          #數據庫用戶名
        'PASSWORD': 'abc',            #數據庫用戶名密碼
        'HOST': '',
        'PORT': '5432',             #數據庫遠程鏈接端口
    }
}

 

配置完後,code

執行 ip

python manage.py migrate

 

初始化數據庫

 

Reference:

http://stackoverflow.com/questions/5420789/how-to-install-psycopg2-with-pip-on-python

http://stackoverflow.com/questions/32123068/pycharm-django-postgresql

相關文章
相關標籤/搜索