#mysql #django #mariadb #geodjango
#mysql #django #mariadb #geodjango
Вопрос:
Я пытаюсь использовать PointField из пакета GeoDjango, и всякий раз, когда я пытаюсь просмотреть объект модели с сохраненной точкой, я получаю следующее исключение:
Environment:
Request Method: GET
Request URL: http://localhost:1989/admin/world/worldborder/6/
Django Version: 1.6.2
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'world')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
432. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
198. return view(request, *args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
29. return bound_func(*args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
25. return func(self, *args2, **kwargs2)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
339. return func(*args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in change_view
1237. form = ModelForm(instance=obj)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/forms/models.py" in __init__
315. object_data = model_to_dict(instance, opts.fields, opts.exclude)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/forms/models.py" in model_to_dict
143. data[f.name] = f.value_from_object(instance)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in value_from_object
560. return getattr(obj, self.attname)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/contrib/gis/db/models/proxy.py" in __get__
40. geom = self._klass(geom_value)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/contrib/gis/geos/geometry.py" in __init__
65. geo_input = force_text(geo_input)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/utils/encoding.py" in force_text
116. raise DjangoUnicodeDecodeError(s, *e.args)
Exception Type: DjangoUnicodeDecodeError at /admin/world/worldborder/6/
Exception Value: 'utf8' codec can't decode byte 0xc0 in position 16: invalid start byte. You passed in 'x00x00x00x00x01x01x00x00x00x00x00x00x00x00,0xc08x00x00x00pxdfx19@' (<type 'str'>)
Моя модель выглядит так:
from django.contrib.gis.db import models
# Create your models here.
class WorldBorder(models.Model):
# Regular Django fields corresponding to the attributes in the
# world borders shapefile.
name = models.CharField(max_length=50)
location = models.PointField(null=False, blank=False, srid=4326, verbose_name="Location")
# Returns the string representation of the model.
# On Python 3: def __str__(self):
def __unicode__(self):
return self.name
Я использую MariaDB 5.5.38. Для таблицы PointField установлено значение MyISAM, и я пробовал использовать кодировку latin1 и UTF-8.
Есть идеи, что может вызвать это?
Спасибо, Марк
Ответ №1:
Ответ в том, что я забыл добавить эту важную строку в модель:
objects = models.GeoManager()
Комментарии:
1. Не совсем понятно, где вы это добавили. Может быть, вы могли бы быть немного более конкретными?