Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GeoDjango & MySQL: points can't be NULL, what other "empty" value should I use?

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?

like image 971
Benjamin Wohlwend Avatar asked Nov 03 '10 09:11

Benjamin Wohlwend


2 Answers

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.

like image 138
Gintautas Miliauskas Avatar answered Oct 12 '22 23:10

Gintautas Miliauskas


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)
like image 29
birdsarah Avatar answered Oct 12 '22 21:10

birdsarah