Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value too long for type character varying(42) #53

Open
aaj opened this issue Sep 23, 2015 · 6 comments
Open

Value too long for type character varying(42) #53

aaj opened this issue Sep 23, 2015 · 6 comments

Comments

@aaj
Copy link

aaj commented Sep 23, 2015

I have a model with a GeoPosition field in it. When I create a new instance through the admin, I get the nice map widget that lets me pinpoint the location. However, when I try to save certain locations, I get an exception thrown:

value too long for type character varying(42)

I checked the table of my model in the DB and the geoposition field is the only column defined as varchar(42).

The way I chose that location seems to be part of the issue. If I drag the icon to where I want it, it seems to work. This is the way I've been doing it so far, but today while filling out the admin form, I tabbed through all the fields until I got to the latitude field, at which point the map zoomed in to a spot in the ocean. Since I'm still testing my app, I moved the icon to any random spot of that part of the ocean, saw the lat/long widgets be filled with random coordinates, and kept on filling out the form.

When I did it this way, the latitude and longitude fields had many decimal places in them, apparently more than the DB column can hold, which django was happy to point out to me in the form of an exception.

I have no idea what the standard is for latitude and longitude number length, or if there even is a standard, but perhaps the max length of that column can be increased to something that plays nice with the admin widget?

@yuvadm
Copy link

yuvadm commented Dec 3, 2015

I'm also seeing this behavior in Django 1.9 (#58)

@yuvadm
Copy link

yuvadm commented Dec 3, 2015

This seems to be the root cause on the #58 branch:

~/.virtualenvs/proj/lib/python3.4/site-packages/django/db/models/query.py in _update
            return query.get_compiler(self.db).execute_sql(CURSOR)
     ...

▼ Local vars
Variable    Value
query   

<django.db.models.sql.subqueries.UpdateQuery object at 0x1124d45f8>

self    

[<Place: foo>]

values  

[
 (<django.db.models.fields.CharField: name>, None, 'foo'),
 (<geoposition.fields.GeopositionField: position>,
  None,
  [Decimal('40.7127837'), Decimal('-74.00594130000002')])
]

Really not sure why this is returning as a list of Decimals.

@yuvadm
Copy link

yuvadm commented Dec 3, 2015

Fixed on #58

@zelds
Copy link

zelds commented Jan 8, 2017

Have this error in
Django==1.10.4
django-geoposition==0.3.0

@stefanogorla
Copy link

Me too, with Django 1.10.2, django-geoposition 0.3.0 and PostgreSQL Database

@koztay
Copy link

koztay commented Oct 18, 2017

I had the same problem with a CreateView of my project and find the solution. The problem is that the Decimal lat and long coordinates are not expected when creating a model instance. The location field must be the Geoposition instance. So, you should import this class as the following :

from geoposition import Geoposition

and create instance and pass this instance in form_valid as like as the following:

if place.is_valid():
    cd = place.cleaned_data
    location = cd.get('location')
    geo_location = Geoposition(location[0], location[1])
    place_obj, created = PlaceOfEvent.objects.get_or_create(location=geo_location)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants