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?
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:
from django.contrib.gis.db import models
class Event(models.Model):
address = models.TextField()
point = models.PointField('coordinates', null=True, blank=True, spatial_index=False)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With