小编典典

执行syncdb时,获取“ DatabaseOperations”对象没有属性“ geo_db_type”错误

django

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

AttributeError:“ DatabaseOperations”对象没有属性“ geo_db_type”

我所有的 研究都得出了相同的解决方案:确保用作数据库引擎。有趣的是,我已经这样做了(我也有在): django.contrib.gis.db.backends.postgisdjango.contrib.gisINSTALLED_APPS

settings.py

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

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

还有其他我想念的东西吗?非常感谢您的帮助,以下是完整的错误跟踪供参考:

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'

阅读 597

收藏
2020-03-31

共1个答案

小编典典

该OP是使用GeoDjango内置buildpack,但如果有人在这里得到使用地理buildpack和dj_database_url喜欢我,在settings.py不要忘记最后一行:

import dj_database_url
DATABASES['default'] = dj_database_url.config()
DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'

更新

dj_database_url直接支持 PostGIS。如果可以将数据库URL更改为以开头,则可以不用上面代码的最后一行postgis

2020-03-31