so I am writing migration which will assign latitude and longitude values to PointField in every record of database.
I have one solution which works but it is too slow for a 10 000 000 records of database. So I can update every record in for loop by simply assigning lat and long to a point and then save a record. But I wanted to use Django's .update() method to do this much faster.
class Listing(AirbnbModel):
latitude = models.DecimalField()
longitude = models.DecimalField()
point = PointField(srid=4326, geography=True, null=True) # new field
This works but takes too much time and it is almost impossible to do this for 10 000 000 records
for listing in Listing.objects.all():
listing.point = Point(float(listing.latitude), float(listing.longitude))
listing.save()
Here is what I tried to do but I got an error.
Listing.objects.all().update(point=ExpressionWrapper(F('latitude'), F('longitude') , output_field=PointField()))
I tried this as well
Listing.objects.all().update(point=ExpressionWrapper(Point(Value('latitude'), Value('longitude')), output_field=PointField()))
But this does not work at all.