[Fixed]-Django JSON field. 'module' object has no attribute 'JSONField'


There’s no JSONField in models. But there’s a handy jsonfield package available to use JSONField in Django models. To install the package, do:

pip install jsonfield

Once installed, do:

from jsonfield import JSONField
from django.db import models

class Question(models.Model):
question_text = JSONField(max_length=200)
pub_date = models.DateTimeField('date published')


There’s no JSONField in models module, you need to:

from django.contrib.postgres.fields import JSONField

class Question(models.Model):
    question_text = JSONField()

Django doc about JSONField.


Django 3.1 update

Starting with Django 3.1, the JSONField is now available for all database backends.



Changing the import statement should fix your problem (it helped me):

from django.contrib.postgres.fields.jsonb import JSONField

So JSONField is located in jsonb module now.

Leave a comment