So I am trying to add a point field to a model in django which looks like this:
class Location(models.Model):
lat = models.FloatField(blank=True, null=True)
lng = models.FloatField(blank=True,null=True)
geometry = models.PointField(srid=4326,default='POINT(0.0,0.0)')
objects = models.GeoManager()
I already have database with lots of locations with the lat lng coordinates but they don't need a point field. I am getting this error django.db.utils.IntegrityError: column "geometry" contains null values
I set the default but it still gives me that error when I run 'python manage.py migrate' How can I fix this?
Thedefault
does not change old rows in the database (that existed before the migration). You should set the thegeometry
field to be nullable and then migrate. Once migrated you can either fill in the null values with the default and removenull=True
or leave as isUPDATE
Based on this post it seems very possible that
PointField
cannot benull
(even if it's specified to be which really grinds my gears...). GIVEN that your model does not need to change but it doesn't look like django can handle this super well for you.I see two options (better ones might exist)
Neither of these seem ideal but the googles have not yet shown me a better way