Django 1.10.5; Postgis db作为默认后端时出错

时间:2019-10-21 15:29:40

标签: python django geodjango

我对开发和django都是新手。目前,在将默认数据库引擎设置更改为

后,使用“ python manage.py runserver”命令时出现以下错误
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'agricom',
        'USER': 'postgres',
        'HOST': 'localhost',
        'PASSWORD': 'pass',
        'PORT': '5432',
    }
}

我收到以下错误;

  

无法从'django.contrib.gis.gdal'中导入名称'GDALRaster'

(vrtenv_dj1-105) C:\Users\Kevin\Documents\Django_PJs\agricom>py manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper 
at 0x046C46F0>
Traceback (most recent call last):
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\db\utils.py", line 115, in load_backend
    return import_module('%s.base' % backend_name)
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked     
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module        
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed   
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\contrib\gis\db\backends\postgis\base.py", line 7, in <module>
    from .operations import PostGISOperations
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\contrib\gis\db\backends\postgis\operations.py", line 7, in <module>
    from django.contrib.gis.gdal import GDALRaster
ImportError: cannot import name 'GDALRaster' from 'django.contrib.gis.gdal' (C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\contrib\gis\gdal\__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\core\management\commands\runserver.py", line 113, in inner_run
    autoreload.raise_last_exception()
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\utils\six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\apps\registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\apps\config.py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked     
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed   
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager  
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>
    class AbstractBaseUser(models.Model):
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\db\models\base.py", line 119, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\db\models\base.py", line 316, in add_to_class
    value.contribute_to_class(cls, name)
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\db\models\options.py", line 214, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\db\utils.py", line 211, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\db\utils.py", line 134, in load_backend
    raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.postgis' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
    'mysql', 'oracle', 'postgresql', 'sqlite3'
Error was: cannot import name 'GDALRaster' from 'django.contrib.gis.gdal' (C:\Users\Kevin\Documents\Django_PJs\vrtenv_dj1-105\lib\site-packages\django\contrib\gis\gdal\__init__.py)

我该怎么办?

请在下面找到错误消息:

error message

0 个答案:

没有答案