Take this model:
from django.contrib.gis.db import models
class Location(models.Model):
point = models.PointField(null=True, blank=True)
Then try to execute this, deliberately giving it a wrong SRID:
from django.contrib.gis.geos import Point
from testpoint.models import Location
some_location = Location()
some_location.point = Point(x=15, y=16, srid=210)
some_location.save()
Upon executing the last statement, some_location.save()
, the message "unknown SRID: 210" is shown on the console. So far so good. The problem is that the .save()
returns successfully, and null is stored in point
; but what I want is for nothing to be saved and for an exception to be raised.
Django appears to send this SQL to spatialite:
INSERT INTO "testpoint_location" ("point")
VALUES (Transform(GeomFromText('POINT(15.0 16.0)', 210), 4326))
and spatialite appears to execute it (with the warning printed on the console) without ever telling Django that something went wrong.
How can I tell spatialite to fail and return an error when the SRID is wrong?