Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
858 views
in Technique[技术] by (71.8m points)

django - Getting 'DatabaseOperations' object has no attribute 'geo_db_type' error when doing a 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The OP was using the GeoDjango buildpack, but in case anyone gets here using Geo buildpack and dj_database_url like I was, in settings.py don't forget the last line:

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

UPDATE

dj_database_url directly supports PostGIS. You can do without the last line in the code above if you can change your database URL to start with postgis.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...