GeoDjango 和MySQL:点不能为NULL,还有什么“空”?我应该使用的值?
我有这个 Django 模型:
from django.contrib.gis.db import models
class Event(models.Model):
address = models.TextField()
point = models.PointField('coordinates', null=True, blank=True)
当我使用 MySQL 同步此模型时,创建索引时会打印此错误消息:
Failed to install index for events.Event model: (1252, 'All parts of a SPATIAL index must be NOT NULL')
因此,无法使用 null=True
(假设我想要拥有该索引) ,我还有什么其他的可能性?我可以将点 (0,0) 定义为“空”,但是我必须记住我计划使用数据的所有地方的约定,否则很多事件将发生在非洲西部大西洋的某个地方......
还有哪些其他可能性?
I have this Django model:
from django.contrib.gis.db import models
class Event(models.Model):
address = models.TextField()
point = models.PointField('coordinates', null=True, blank=True)
When I sync this model using MySQL, this error message is printed while creating indexes:
Failed to install index for events.Event model: (1252, 'All parts of a SPATIAL index must be NOT NULL')
so, not being able to use null=True
(given that I want to have that index), what other possibilities do I have? I could define the point (0,0) as "empty", but then I have to remember that convention everywhere I plan to use the data, otherwise a whole lot of events will take place somewhere in the Atlantic west of Africa...
What other possibilities are there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你在这里没有太多选择。您可以使用占位符(例如 (0, 0)),也可以将该点封装在一个对象中,并在需要该点的任何地方引用该对象。这样,对对象的引用可以为空,但额外的连接会损害性能并使事情变得复杂。
I don't think you have many options here. Either you use a placeholder such as (0, 0), or you encapsulate the point in an object and reference the object everywhere you need the point. That way the reference to the object could be made nullable, but the extra join would hurt performance and complicate things.
我刚刚遇到了同样的问题。对我来说,我需要指定不创建空间索引。所以你的模型将更改为:
I just had the same issue. For me, I needed to specify to not make a spatial_index. So your model would change to:
一个快速的想法是有另一个布尔字段,当您有实际点时将其标记为真/假。这将使查询变得容易,因为您可以将布尔字段添加到 where 子句。
A quick idea would be to have another boolean field that you mark as true/false when you have an actual point. It would make querying easy because you could add the boolean field to the where clause.