Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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',
    },
}
like image 252
Valachio Avatar asked May 16 '26 15:05

Valachio


1 Answers

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': '',
    }
}
like image 187
alfredo138923 Avatar answered May 20 '26 01:05

alfredo138923