3

I'm trying to get GeoDjango running on SpatiaLite on Ubuntu 11.04, and even with a very minimal setup, I'm hitting a strange error. Saving an instance of a model with geo-fields works, but loading it again fails with an exception:

Error encountered checking Geometry returned from GEOS C function "GEOSWKBReader_read_r".

relevant parts of my settings.py

DATABASES = {
    'default': {
    'ENGINE': 'django.contrib.gis.db.backends.spatialite',
        'NAME': '/tmp/test.db',
    }
}

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'django.contrib.gis',
    'testapp',
)

testapp.models:

from django.contrib.gis.db import models

class TestModel(models.Model):
    name = models.CharField(max_length=10)
    location = models.PointField()

testapp.admin

from django.contrib.gis import admin

from testapp.models import TestModel

admin.site.register(TestModel, admin.OSMGeoAdmin)

/edit: the same exact code works without problems on PostgreSQL/postgis

Benjamin Wohlwend
  • 30,958
  • 11
  • 90
  • 100

1 Answers1

5

OK, I found the problem myself: I forgot to use models.GeoManager as the default manager. This fixes my problem:

class TestModel(models.Model):
    name = models.CharField(max_length=10)
    location = models.PointField()

    objects = models.GeoManager()
Benjamin Wohlwend
  • 30,958
  • 11
  • 90
  • 100