Добрый день всем!
У меня такая проблема:
Есть модель
class Test(models.Model):
"""
The model of the test
"""
# The name of the test
name = models.CharField(max_length=500)
# The description of test
description = models.TextField(blank=True)
# The test
test = models.BinaryField(blank=True)
# The author of the test
author = models.ForeignKey(settings.AUTH_USER_MODEL)
# The category of the test
category = models.ForeignKey(Category)
# date and time of create test
date_and_time = models.DateTimeField(default=timezone.now())
# How many users complete this test.
rating = models.IntegerField(default=0)
# Public or not public test
is_public = models.BooleanField(default=True)
def __str__(self):
return self.name
При попытки создаю класс Test, заполняю его, и сохнаняю. В результате получаю ошибку:
Exception Type: UnicodeDecodeError
Exception Value: 'utf-8' codec can't decode byte 0x80 in position 74: invalid start byte
Стектрейс:
(django17)11:45 ~/exam_project (master)$ python3 populate_exam.py
Starting Exam population script...
Traceback (most recent call last):
File "populate_exam.py", line 214, in <module>
populate()
File "populate_exam.py", line 40, in populate
category1
File "populate_exam.py", line 208, in add_test
)[0]
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/query.py", line 422, in get_or_create
return self.get(**lookup), False
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/query.py", line 351, in get
num = len(clone)
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/query.py", line 122, in __len__
self._fetch_all()
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/query.py", line 966, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/query.py", line 265, in iterator
for row in compiler.results_iter():
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 700, in results_iter
for rows in self.execute_sql(MULTI):
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
cursor.execute(sql, params)
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/backends/utils.py", line 85, in execute
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/mysql/connector/django/base.py", line 377, in last_executed_query
return cursor.statement
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/mysql/connector/django/base.py", line 153, in __getattr__
return getattr(self.cursor, attr)
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/mysql/connector/cursor.py", line 858, in statement
return self._executed.strip().decode('utf8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 265: invalid start byte
(django17)11:45 ~/exam_project (master)$
Ошибка моделируется только в MySql, в sqlite всё отлично работает.
Использую Django 1.7.7 и python3.4
Подозреваю что не может записать данные в поле типа BinaryField
Кто сталкивался с подобной проблемой? Как исправить?