7

I am working on a django project, where I want to create gin indexing on my model's attribute. I want to create gin indexing on

 SchoolName = models.CharField(max_length=200, blank=False, null=False)

But, I am getting this error

 django.db.utils.ProgrammingError: data type character varying has no default operator class for access method "gin"

Help me to figure out this error

6
  • 1
    Can you put the traceback also the code where you use "gin" method? Commented Apr 19, 2018 at 14:00
  • i can not share the codes. But i can give you details. Actually i want to create indexing on charfield of my school model in djnago so that i can perform trigram search on the schoolname. Commented Apr 20, 2018 at 5:04
  • class Meta: indexes = [GinIndex(fields=['Field_Name'])] this is how i am creating gin index on schoolname attribute of school model. Commented Apr 20, 2018 at 5:05
  • @Sweta Looks like the SchoolName field does not have a built-in operator class in Postgres See built-in operator classes here: postgresql.org/docs/current/static/gin-builtin-opclasses.html Also see Django documentation on how to handle this by installing a btree_gin_extension here: docs.djangoproject.com/en/2.0/ref/contrib/postgres/indexes/… This will allow support for char, varchar e.t.c Commented Apr 20, 2018 at 7:17
  • how to install BtreeGinExtension in ubuntu16.09 Commented Apr 20, 2018 at 8:53

1 Answer 1

11

Create a migrations file to install the BtreeGinExtension to enable GIN Indexes to be built on varchar data types.

from django.contrib.postgres.operations import BtreeGinExtension

class Migration(migrations.Migration):
    ...

    operations = [
        BtreeGinExtension(),
        ...
    ]

References:

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

3 Comments

Hi, which migrations file should I add this too if I already have data and an existing schema?
where does the migrations file go? what is the rest of the code?
This need to be added in the migrations files that gets generated after ./manage.py makemigrations command

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.