Python Forum

Full Version: django-geoposition and unknown column error?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I am using django geolocation for showing map with position in my application built on Django2.0.6 + Python3.6 + Mysql.
But when I open my form it shows following error-

Exception Value:
(1054, "Unknown column 'building.position' in 'field list'")

Do I need to create a field position in my database? It is not mentioned in the document anywhere.
from geoposition.fields import GeopositionField
class Building(models.Model):
  postal_code = models.CharField(max_length=6)
  address = models.TextField()
  latitude = models.FloatField(validators=[MinValueValidator(-90.0), MaxValueValidator(90.0)])
  longitude = models.FloatField(validators=[MinValueValidator(-180.0), MaxValueValidator(180.0)])
  position = GeopositionField()

  class Meta:
    managed = False
    db_table = 'building'
Isn't everything in a model a column in the underlying database? How else would the spacial location be saved?

In mysql, I think the column type you'd want is geometry: https://dev.mysql.com/doc/refman/8.0/en/...rview.html
db_table Naming issues

class Meta:
    managed = False
    db_table = '"building"'
Or maybe...

class Meta:
    managed = False
    fields = ('postal_code','address','latitude','longitude','position')
(Jun-22-2018, 04:22 PM)nilamo Wrote: [ -> ]Isn't everything in a model a column in the underlying database? How else would the spacial location be saved?

In mysql, I think the column type you'd want is geometry: https://dev.mysql.com/doc/refman/8.0/en/...rview.html

Yes, everything in a model is a column in the underlying database.
And thanks for sharing the spatial data type, it helps!

Sharing my solution what I have done to achieve this-
The django-location-filed package does not work properly with django 2.0.6; we need to add position field in database but prior to the 2.0 version it works without adding any new field.

So instead of this package I used Google Map Api and with the help of some jquery code I am able to proceed.