Getting 'DatabaseOperations' object has no attribute 'geo_db_type' error when doing a syncdb Getting 'DatabaseOperations' object has no attribute 'geo_db_type' error when doing a syncdb heroku heroku

Getting 'DatabaseOperations' object has no attribute 'geo_db_type' error when doing a syncdb


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_urlDATABASES['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.


I got this error when trying to run tests with the test db set like so:

if 'test' in sys.argv:    DATABASES = {        'default': {            'ENGINE': 'django.db.backends.sqlite3',             'NAME': '_testdb',        }    }

The problem is that the sqlite3 DatabaseOperations object doesn't have the attribute geo_db_type (like the title of this post suggests).

My solution was to change the backend to the sqlite equivalent GIS engine:

        'ENGINE': 'django.contrib.gis.db.backends.spatialite'

See the Django docs on GeoDjango installation for all the possible backends, with installation instructions: https://docs.djangoproject.com/en/3.0/ref/contrib/gis/install/#spatial-database


I was having the same problem and I had to change:

'ENGINE': 'django.db.backends.postgresql_psycopg2',

to:

'ENGINE': 'django.contrib.gis.db.backends.postgis',