4

I am trying to define a model with one column being a mysql json type. Searching on web results in suggestions related to django's postgresql support for JSONField type or django-jsonfield.

Is there currently no way django natively supports mysql's json type. Also while doing inspectdb a column of type json in mysql was assigned the type TextField with a comment This field type is a guess.

How would I declare my model in such a way that it supports json fields?

3 Answers 3

9

UPDATE

As of Django 3.2, it now supports JSONField and django-mysql JSONField is now deprecated.


Check out django-mysql.

Django-MySQL supports the JSON data type and related functions through JSONField plus some JSON database functions.

Sign up to request clarification or add additional context in comments.

2 Comments

does it work along with normal django models, i.e. the ones from django.db?
Sure, look at the examples.
0

You've already found django-jsonfield, but here are some recent discussions you may be interested in:

https://groups.google.com/forum/#!searchin/django-developers/mysql$20json%7Csort:relevance/django-developers/zfred27yVPg/U-4iNd_aAQAJ

https://groups.google.com/forum/#!searchin/django-developers/mysql$20json%7Csort:relevance/django-developers/sAgYOqBUvgI/aLQH6vx5CAAJ

AFAIK there isn't anything native currently, but people seem interested in developing what you're looking for.

Comments

0

JSONField is supported on MariaDB 10.2.7+, MySQL 5.7.8+, Oracle, PostgreSQL, and SQLite 3.9.0+ (with the JSON1 extension enabled).

Details here: https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.JSONField

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.