执行同步数据库时,获取“DatabaseOperations"对象没有属性“geo_db_type"错误 [英] Getting 'DatabaseOperations' object has no attribute 'geo_db_type' error when doing a syncdb

查看:21
本文介绍了执行同步数据库时,获取“DatabaseOperations"对象没有属性“geo_db_type"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Heroku 上的 GeoDjango 应用程序上运行 heroku run python manage.py syncdb,但出现以下错误:

I'm attempting to run heroku run python manage.py syncdb on my GeoDjango app on Heroku, but I get the following error:

AttributeError: 'DatabaseOperations' 对象没有属性 'geo_db_type'

全部 of 我的 研究 得出了相同的解决方案:确保使用 django.contrib.gis.db.backends.postgis 作为数据库引擎.有趣的是,我已经这样做了(而且我在 INSTALLED_APPS 中也有 django.contrib.gis):

All of my research has yielded the same solution: make sure to use django.contrib.gis.db.backends.postgis as the database engine. Funny thing is that I'm already doing this (and I also have django.contrib.gis in INSTALLED_APPS):

settings.py

DATABASES = {
  'default': {
    'ENGINE': 'django.contrib.gis.db.backends.postgis',
    'NAME': '...',
    'HOST': '...',
    'PORT': ...,
    'USER': '...',
    'PASSWORD': '...'
  }
}

INSTALLED_APPS = (
    ...,
    'django.contrib.gis',
)

还有什么我想念的吗?非常感谢任何帮助,以下是完整的错误跟踪供参考:

Is there something else I am missing? Any help is greatly appreciated, below is the full error trace for reference:

Running `python manage.py syncdb` attached to terminal... up, run.1
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/app/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/app/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/app/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/app/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 91, in handle_noargs
    sql, references = connection.creation.sql_create_model(model, self.style, seen_models)
  File "/app/lib/python2.7/site-packages/django/db/backends/creation.py", line 44, in sql_create_model
    col_type = f.db_type(connection=self.connection)
  File "/app/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py", line 200, in db_type
    return connection.ops.geo_db_type(self)
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'

更新:我遵循了GeoDjango 教程Heroku/Django 教程,并构建了一个可以在我的开发机器上运行的简单应用程序.我使用 自定义 GeoDjango buildpack 将它推送到 Heroku,并尝试了 syncdb,但得到了同样的错误.这是 Django/GeoDjango、Heroku 或 buildpack 的问题吗?我的开发环境使用 PostgreSQL 9.1 和 PostGIS 2.0,但 Heroku 使用 9.0.9 和 1.5,这可能是问题吗?

Update: I followed the GeoDjango tutorial and Heroku/Django tutorial, and built a simple app that works on my dev machine. I pushed it to Heroku using a custom GeoDjango buildpack, and tried syncdb, but get the same error. Is this an issue with Django/GeoDjango, Heroku, or the buildpack? My dev environment is using PostgreSQL 9.1 and PostGIS 2.0, but Heroku uses 9.0.9 and 1.5, could that be the issue?

推荐答案

buildpack 是这里的罪魁祸首.我没有使用 Heroku 的 buildpack 页面 上列出的 GeoDjango buildpack,而是使用了 其中一个分支最近更新了.

The buildpack was the primary culprit here. Instead of using the GeoDjango buildpack listed on Heroku's buildpack page, I used one of it's forks that was updated more recently.

此外,当我执行 git push heroku master 时,Heroku 会为应用程序创建一个开发数据库,​​而当我执行同步数据库时,我的 DATABASES 设置被忽略并且 Heroku 尝试使用 dev 数据库相反……显然是一个问题,因为开发数据库没有/不能安装 PostGIS.所以我在使用 git push(使用 正确的构建包),然后运行syncdb,它就可以工作了.

Also, when I do a git push heroku master, Heroku creates a dev database for the app, and when I do a syncdb, my DATABASES setting is ignored and Heroku tries to use the dev database instead... obviously an issue, because dev databases don't/can't have PostGIS installed. So I destroyed the dev database after it was created with the git push (with the correct buildpack), then ran syncdb and it works.

这篇关于执行同步数据库时,获取“DatabaseOperations"对象没有属性“geo_db_type"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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