ImportError: cannot import name 'KeyTextTransform' from 'django.contrib.postgres.fields.jsonb'

What is the new import for:

ImportError: cannot import name 'KeyTextTransform' from 'django.contrib.postgres.fields.jsonb'

I did some internet searching and didn't find an immediate result for the error.

I am trying to upgrade from django 3.2 to django 4.1.2

It looks like the field type was migrated to the following location:

django.db.models.fields.json.KeyTextTransform

So for django4+:

from django.db.models.fields.json import KeyTextTransform

Instead of:

from django.contrib.postgres.fields.jsonb import KeyTextTransform
Back to Top