Django - Using PostGIS database with PostgreSQL database, do I need 2 databases?
Asked Answered
L

1

9

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',
    },
}
Lobule answered 1/5, 2018 at 22:18 Comment(0)
V
14

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': '',
    }
}
Viscid answered 1/5, 2018 at 22:25 Comment(2)
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?Lobule
You're right. django.contrib.gis.db.backends.postgis just extends django.db.backends.postgresql_psycopg2 to add the PostGiS types.Viscid

© 2022 - 2024 — McMap. All rights reserved.