Django - 将PostGIS数据库与PostgreSQL数据库一起使用,我需要2个数据库吗?

时间:2018-05-01 22:18:16

标签: django geodjango django-postgresql

我目前正在使用单个PostgreSQL数据库,标准设置。

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

我的问题是,我可以继续使用默认的postgres设置,只需在shell中执行CREATE EXTENSION postgis即可访问postgis功能吗?或者我需要单独添加postgis数据库,如下所示:

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',
    },
}

1 个答案:

答案 0 :(得分:1)

您可以继续使用默认的postgres设置,只需将引擎更改为:django.contrib.gis.db.backends.postgis

即可
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': password,
        'HOST': 'localhost',
        'PORT': '',
    }
}
相关问题