7

I'm currently using a single PostgreSQL database, with standard settings.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': password,
        'HOST': 'localhost',
        'PORT': '',
    }
}

My question is, can I keep using the default postgres setup, and just perform CREATE EXTENSION postgis in the shell to get access to postgis features? Or do I need to add a postgis database separately, like below:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': password,
        'HOST': 'localhost',
        'PORT': '',
    }
    'geodata': {
         'ENGINE': 'django.contrib.gis.db.backends.postgis',
         'NAME': 'geodjango',
         'USER': 'geo',
    },
}
Valachio
  • 1,025
  • 2
  • 18
  • 40

1 Answers1

13

You can keep using the default postgres setup, just changing the engine to: django.contrib.gis.db.backends.postgis

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': password,
        'HOST': 'localhost',
        'PORT': '',
    }
}
alfredo138923
  • 1,509
  • 1
  • 15
  • 15
  • Ah so I am guessing `django.contrib.gis.db.backends.postgis` is an extension that includes everything in `django.db.backends.postgresql_psycopg2` plus geo-specific features? – Valachio May 01 '18 at 22:41
  • 2
    You're right. django.contrib.gis.db.backends.postgis just extends django.db.backends.postgresql_psycopg2 to add the PostGiS types. – alfredo138923 May 02 '18 at 02:51