Django 1.9 - JSONField in Models

Django JSONField is Postgres only.

https://docs.djangoproject.com/en/3.0/ref/contrib/postgres/fields/#django.contrib.postgres.fields.JSONField

UPDATE:

There is support for MYSQL via 3rd party library django-mysql


# 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 detail:https://pypi.python.org/pypi/django-jsonfield


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.

Tags:

Django