简体   繁体   English

配置Postgresql POSTGIS数据库

[英]Configuring a Postgresql POSTGIS database

First off, I am new to django. 首先,我是django的新手。 I am trying to use GeoLite(GeoIP2) datasets in my POSTGIS database in Django 1.10. 我正在尝试在Django 1.10的POSTGIS数据库中使用GeoLite(GeoIP2)数据集。 When I attempt to configure the myapp/settings.py file, i get error messages.There seem to be database backends in different paths in the django directory;Can you please clarify why? 当我尝试配置myapp / settings.py文件时,我收到错误消息。django目录中的不同路径中似乎有数据库后端;您能否阐明原因?

  1. django\\contrib\\gis\\db\\backends\\postgis django \\ contrib \\ gis \\ db \\ backends \\ postgis
  2. django\\db\\backends django \\ db \\后端

After activating my python3 virtual environment, when i try to set the default database in my settings.py file as postgresql('django.db.backends.postgresql'), i get an error: 激活python3虚拟环境后,当我尝试将settings.py文件中的默认数据库设置为postgresql('django.db.backends.postgresql')时,出现错误:

AttributeError:”Database Operations’ object has no attribute ‘geo_db_type’.

When i try to use POSTGIS as my database engine (i set the GDAL_LIBRARY_PATH in my virtual environment), i get an error: 当我尝试使用POSTGIS作为数据库引擎时(我在虚拟环境中设置了GDAL_LIBRARY_PATH),出现错误:

django.contrib.gis.db.backends.postgis' is not an available database backend. Try using 'django.db.backends.XXX', where XXX is one of 'mysql', 'oracle', 'postgresql',and 'sqlite'.
Error was: Cannot import name ‘GDALRaster’.

Can you suggest possible solutions to the above error messages? 您能否建议上述错误消息的解决方案? Thank you. 谢谢。

Installed GDAL from Christopher Gohlke's site (32 bit GDAL-2.0.3-cp35-cp35m-win32.whl)into the virtual environment. 从Christopher Gohlke的站点(32位GDAL-2.0.3-cp35-cp35m-win32.whl)安装了GDAL到虚拟环境中。 Download OSGEO4W (32 bit) and install the Express Web option. 下载OSGEO4W(32位)并安装Express Web选件。 Create Environment Variables. 创建环境变量。 Set the environment variables as below: 如下设置环境变量:

set PYTHON_ROOT=C:\\Python35-32 set GDAL_DATA=C:\\Program Files\\PostgreSQL\\9.6\\gdal-data set PROJ_LIB=C:\\Program Files\\PostgreSQL\\9.6\\share\\contrib\\postgis\\proj set PATH=%PATH%;%PYTHON_ROOT%;%OSGEO4W_ROOT%\\bin reg ADD "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" /v Path /t REG_EXPAND_SZ /f /d "%PATH%" reg ADD "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" /v GDAL_DATA /t REG_EXPAND_SZ /f /d "%GDAL_DATA%" reg ADD "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" /v PROJ_LIB /t REG_EXPAND_SZ /f /d "%PROJ_LIB%" 设置PYTHON_ROOT = C:\\ Python35-32设置GDAL_DATA = C:\\ Program Files \\ PostgreSQL \\ 9.6 \\ gdal-data设置PROJ_LIB = C:\\ Program Files \\ PostgreSQL \\ 9.6 \\ share \\ contrib \\ postgis \\ proj设置PATH =%PATH %;%PYTHON_ROOT%;%OSGEO4W_ROOT%\\ bin reg添加“ HKLM \\ SYSTEM \\ CurrentControlSet \\ Control \\ Session Manager \\ Environment” / v路径/ t REG_EXPAND_SZ / f / d“%PATH%” reg添加“ HKLM \\ SYSTEM \\ CurrentControlSet \\ Control \\ Session Manager \\ Environment” / v GDAL_DATA / t REG_EXPAND_SZ / f / d“%GDAL_DATA%” reg ADD“ HKLM \\ SYSTEM \\ CurrentControlSet \\ Control \\ Session Manager \\ Environment” / v PROJ_LIB / t REG_EXPAND_SZ / f / d“ %PROJ_LIB%”

I also set LD_LIBRARY_PATH as C:\\Python35-32\\myvenv_python3\\Lib\\site-packages\\osgeo. 我还将LD_LIBRARY_PATH设置为C:\\ Python35-32 \\ myvenv_python3 \\ Lib \\ site-packages \\ osgeo。 Then, the database is Improperly configured and cannot import 'GDALRaster' went away.From your django project directory, it would be possible to migrate now using: python manage.py migrate 然后,数据库配置不正确,无法导入'GDALRaster'。从您的django项目目录中,现在可以使用以下命令进行迁移:python manage.py migrate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM