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

问题描述

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



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



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

  settings.py 

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

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

有没有其他的东西我缺少?/ / pre>

任何帮助是非常感谢,下面是完整的错误追踪作为参考:

 运行`python manage.py syncdb`附加到终端... up,run.1 
创建表...
创建表auth_permission
创建表auth_group_permissions
创建表auth_group
创建表auth_user_user_permissions
创建table auth_user_groups
创建表auth_user
创建表django_content_type
创建表django_session
创建表django_site
创建表django_admin_log
追溯(最近的最后一次调用):
文件manage.py,第10行,在< module>
execute_from_command_line(sys.argv)
文件/app/lib/python2.7/site-packages/django/core/management/__init__.py,第443行,在execute_from_command_line
实用程序.execute()
文件/app/lib/python2.7/site-packages/django/core/management/__init__.py,第382行,执行
self.fetch_command(子命令)。 run_from_argv(self.argv)
文件/app/lib/python2.7/site-packages/django/core/management/base.py,第196行,在run_from_argv
self.execute(* args,** options .__ dict__)
文件/app/lib/python2.7/site-packages/django/core/management/base.py,第232行,执行
output = self .handle(* args,** options)
文件/app/lib/python2.7/site-packages/django/core/management/base.py,第371行,处理
返回self.handle_noargs(** options)
文件/app/lib/python2.7/site-packages/django/core/management/commands/syncdb.py,第91行,在handle_noargs
sql ,references = connection.creation.sql_create_model(model,se lf.style,seen_models)
文件/app/lib/python2.7/site-packages/django/db/backends/creation.py,第44行,sql_create_model
col_type = f.db_type (connection = self.connection)
文件/app/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py,第200行,db_type
返回connection.ops.geo_db_type(self)
AttributeError:'DatabaseOperations'对象没有属性'geo_db_type'

更新:我按照,并构建了一个适用于我的开发机器的简单应用程序。我使用将其推送到Heroku,并尝试使用syncdb,但会收到相同的错误。这是Django / GeoDjango,Heroku还是buildpack的问题?我的开发环境是使用PostgreSQL 9.1和PostGIS 2.0,但是Heroku使用9.0.9和1.5,可能是这个问题?

解决方案

buildpack是这里的主要罪魁祸首。而不是使用上列出的GeoDjango构建包,而是使用,最近更新了。



此外,当我做一个 git push heroku master 时,Heroku为应用程序创建了一个开发数据库,​​当我做一个syncdb时,我的 DATABASES 设置被忽略,Heroku尝试使用dev数据库
来显示一个问题,因为dev数据库不/不能有PostGIS安装。因此,在使用 git push (使用),然后运行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' object has no attribute 'geo_db_type'

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'

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?

解决方案

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.

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 databaseinstead... 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.

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

11-03 09:34