【发布时间】:2016-05-03 13:29:27
【问题描述】:
拿这个模型:
from django.contrib.gis.db import models
class Location(models.Model):
point = models.PointField(null=True, blank=True)
然后尝试执行这个,故意给它一个错误的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()
在执行最后一条语句some_location.save() 时,控制台上会显示消息“unknown SRID: 210”。到现在为止还挺好。问题是.save()返回成功,point中存的是null;但我想要的是什么都没有被保存并引发异常。
Django 似乎将此 SQL 发送给了 spatialite:
INSERT INTO "testpoint_location" ("point")
VALUES (Transform(GeomFromText('POINT(15.0 16.0)', 210), 4326))
spatialite 似乎执行了它(在控制台上打印了警告),而没有告诉 Django 出了什么问题。
当 SRID 错误时,如何告诉 spatialite 失败并返回错误?
【问题讨论】:
标签: python django geodjango spatialite