Django迁移说数据库后端不可用 [英] Django Migrations Says Database Backend Isn't Available

查看:125
本文介绍了Django迁移说数据库后端不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Django 1.6.2应用程序升级到1.7.10.我正在使用 Postgres.app 版本9.3.4在Mac上运行PostgreSQL,该版本运行PostgreSQL 9.3.4和PostGIS 2.1 .1.我遇到的问题是,当我运行新的"makemigrations"命令时,出现以下错误(整个stacktrace在底部):

I'm trying to upgrade a Django 1.6.2 application to 1.7.10. I'm running PostgreSQL on my Mac using the Postgres.app version 9.3.4 that runs PostgreSQL 9.3.4 and PostGIS 2.1.1. The problem I'm having is that when I run the new "makemigrations" command, I'm getting the following error (the entire stacktrace is at the bottom):

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:
    u'base', u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: cannot import name BaseSpatialOperations

以下是相关设置:

# conf/settings/base.py
DATABASES = {
    'default': {
        'ENGINE'  : 'django.contrib.gis.db.backends.postgis',
        'NAME'    : 'geodb',
        'USER'    : 'geo',
        'PASSWORD': 'geopassword',   # not really
        'HOST'    : 'localhost',
        'PORT'    : '',
    }
}
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.gis',
    'apps.admin',  # my apps live in an apps subdir.
    'apps.home',
)
POSTGIS_VERSION = (2,1,1)

我在Django 1.6.2应用程序中使用了相同的DATABASE ENGINE设置,没有任何问题.在研究此问题时,其他一些开发人员忘记在其虚拟环境中安装psycopg2,但是我的确安装了2.6.1版.我在Django 1.6.2上使用了2.5.2版本,但是如果我将psycopg2回滚到该版本,我仍然会收到此错误.我已经阅读了这两个版本之间的所有psycopg2发行说明,但没有发现任何可能导致此问题的内容.
Django 1.7 GeoDjango教程也使用此postgis引擎设置,因此它似乎没有被弃用,并且Django 1.7发行说明中没有任何相关内容表明这可能是个问题.

I used this same DATABASE ENGINE setting in my Django 1.6.2 application without any problems. In researching this, some other developers forgot to install psycopg2 in their virtual environment but I do have version 2.6.1 installed in mine. I was using version 2.5.2 with Django 1.6.2 but if I roll psycopg2 back to that version I still get this error. I've read all the psycopg2 release notes between those two versions and didn't see anything that might cause this problem.
The Django 1.7 GeoDjango tutorial also uses this postgis engine setting so it doesn't appear to be deprecated and there isn't anything pertinent in the Django 1.7 release notes that indicate this could be a problem.

我还构建了上面提到的GeoDjango教程的测试版本,如果在其上运行makemigrations命令,则会收到相同的错误.

I also built a test version of the GeoDjango tutorial mentioned above and if I run the makemigrations command on it, I get the very same error.

最后,我完成了一次网络搜索,没有看到任何讨论此迁移/​​数据库引擎问题的文章.有人看到问题了吗?

Finally, I've done a web search and don't see any articles that discuss this migrations/database engine problem. Does anyone see what's wrong?

谢谢!

# Full stacktrace
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/contrib/auth/models.py", line 40, in <module>
    class Permission(models.Model):
  File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/db/models/base.py", line 122, in __new__
    new_class.add_to_class('_meta', Options(meta, **kwargs))
  File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/db/models/base.py", line 297, in add_to_class
    value.contribute_to_class(cls, name)
  File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/db/models/options.py", line 166, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/db/__init__.py", line 40, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/db/utils.py", line 242, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/db/utils.py", line 126, 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:
    u'base', u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: cannot import name BaseSpatialOperations

推荐答案

出于构想,我将Django从1.7.10升级到1.8.4,问题消失了.我不知道为什么要修复它,但是确实可以.

Out of ideas, I upgraded Django from 1.7.10 to 1.8.4 and the problem went away. I don't know why this fixed it but it did.

这篇关于Django迁移说数据库后端不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆