PostgreSQL

確保安裝了一些軟體包:

sudo apt-get install libpq-dev
pip install psycopg2

PostgreSQL 的資料庫設定:

#myapp/settings/settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'myprojectDB',
        'USER': 'myprojectuser',
        'PASSWORD': 'password',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

在舊版本中,你還可以使用別名 django.db.backends.postgresql_psycopg2

使用 Postresql 時,你可以訪問一些額外的功能:

Modelfields:

ArrayField         # A field for storing lists of data. 
HStoreField        # A field for storing mappings of strings to strings. 
JSONField          # A field for storing JSON encoded data. 
IntegerRangeField  # Stores a range of integers 
BigIntegerRangeField # Stores a big range of integers 
FloatRangeField    # Stores a range of floating point values. 
DateTimeRangeField # Stores a range of timestamps