I'm trying to set up a models file in Django 1.9 using the new JSONField. I have found examples using postgres but none with MySql. In the examples with postgres they do a
from django.contrib.postgres.fields import JSONField
How do I go about importing it for MySql? Thanks
UPDATE: Django 3.1 now supports JSONField
natively for multiple databases: https://docs.djangoproject.com/en/dev/releases/3.1/#jsonfield-for-all-supported-database-backends
As stated in other answers, Django's native JSONField (as of 1.9 and 1.10) is for PostgreSQL.
Luckily, MySQL 5.7.8+ comes with a native JSON datatype. You can add it your Django project with the django-mysql package and Django 1.8+
pip install django-mysql
from django.db import models from django_mysql.models import JSONField class MyModel(models.Model): my_json_field = JSONField()
Read more about the django_mysql JSONField here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With