Django 1.9 - JSONField in models

I am trying to customize a model file in Django 1.9 using the new JSONField. I found examples using postgres, but not with MySql. In postgres examples, they do

from django.contrib.postgres.fields import JSONField 

How do I import it for MySql? Thanks

+7
django
source share
3 answers

Django JSONField - Postgres only.

https://docs.djangoproject.com/en/1.9/ref/contrib/postgres/fields/#jsonfield

UPDATE:

There is support for MYSQL through a third-party django-mysql library

+6
source share

As pointed out in other answers, Django native JSONField (as of 1.9 and 1.10) refers to PostgreSQL.

Fortunately, MySQL 5.7+ comes with a native JSON data type . You can add it to 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 django_mysql JSONField here .

+14
source share
 # Install jsonfield package pip install jsonfield # Define my model from django.db import models import jsonfield class MyModel(models.Model): the_json = jsonfield.JSONField() 

More details: https://pypi.python.org/pypi/django-jsonfield

+1
source share

All Articles