I am using mariadb with Server charset: UTF-8 Unicode (utf8mb4)
and python 3.7.3
and for some reason beyond me, a CSV file read in and written to the database is saved in some weird encoding:
models.py:
class Product(models.Model)
data = models.JSONField()
store = models.ForeignKey(Store, on_delete = models.CASCADE)
number = models.PositiveIntegerField()
and when writing to the database with shell:
Product.objects.create(store = store, number = 123, data = {"direction": "süden"})
this reads in the database as:
{"direction": "s\u00fcden"}
but in my database the line reads as "number": 123, "data": {"direction": "s\u00fcden"}
.
I already tried setting the an encoder for the JSONField:
from django.core.serializers.json import DjangoJSONEncoder
...
data = models.JSONField(encoder = DjangoJSONEncoder)
and then ran migrations again. A simple test can be done in the admin, when searching for products süden
returns zero hits. But when manually altering the value to süden
in the db that obviously works. Also, when searching for 123
in the admin, I see the word süden
written correctly.
So my guess is, that I need to implement some kind of equivalent of pythons json ensure_ascii = False
option?
Also I wrote the word süden
to a Charfield
which shows up correctly in the database, without any escapes/encoding errors.