utf-8编解码器无法从数据库解码BinaryField

时间:2018-12-01 16:51:17

标签: django django-models

我目前正在尝试使用Django ORM从数据库中获取二进制数据。

除了CharFields,模型还具有BinaryField。当我获得QuerySet时,无法将其转换为列表,Django会抛出DjangoUnicodeDecodeError。

有什么方法可以解码BinaryField并将QuerySet转换为List?

models.py

class TBL_Form(models.Model):
    name = models.CharField(max_length=150, blank=True, null=True)
    category = models.CharField(max_length=64, blank=True, null=True)
    geometry = models.BinaryField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'Form'

views.py

query = TBL_Form.objects.filter(TBL_Entity).select_related().values_list('id', 'geometry')
[item for item in query ]

错误

  

DjangoUnicodeDecodeError   在/'utf-8'编解码器无法解码字节0xba   位置14:无效的起始字节。你过去了   b'\ x01 \ x00 \ x00 \ x00 \ x01 \ x02 \ x00 \ x00 \ x00 \ x03 \ x00 \ x00 \ x00“ \ xba \ x07W \ xb7 \ xf2 \ xf2 \ xc0 \ xab \ x13 \ xdcW \ xfd} \ xfc \ xc0 \ xe6yz \ xe9 \ xbb \ xf3 \ xf2 \ xc0k \ x91f4u〜\ xfc \ xc0 \ xaeM \ r \ xa2 \ xfa \ xf3 \ xf2 \ xc0,wR \ x0e \ x92〜\ xfc \ xc0'   ()

0 个答案:

没有答案