I am working with GeoDjango for the first time and am having trouble adding a
PointField to my model. Here is my model code:
from django.db import models from django.contrib.gis.geos import Point from django.contrib.gis.db import models class Crime(models.Model): Category = models.CharField(max_length=50) Description = models.CharField(max_length=150) District =models.CharField(max_length=50) Incident = models.IntegerField(default=0) Date = models.DateTimeField(max_length=150,default="") Location = models.PointField()
When I try to create a migration, I get the error:
ValueError: Cannot use object with type float for a geometry lookup parameter.
When I try to create a crime object in the Python shell and save it I get the error:
I’ve been troubleshooting this for quite a while now. I put a debugger in the actual gis library code and found that right before the
ValueError was thrown, it was trying to process the number
35.0 as a geometry object.
I’m wondering if this error either has something to do with needing to set defaults in Django or if something is possibly wrong with my database connection?
It turns out than passing in a default as an array of lat + long , which normally works to create a Point was not a valid option for gis to process when interpreting the schema. Here is a good default for gis point fields should anyone need one.
Figured out this solution by reading through this very old conversation: http://south.aeracode.org/ticket/599
Location = models.PointField(default='POINT(0.0 0.0)')