3

I am trying to add GinIndex to my model however, I am getting an error when migrating:

django.db.utils.ProgrammingError: data type character varying has no default operator class for access method "gin"
HINT:  You must specify an operator class for the index or define a default operator class for the data type.

This is my model:

class Post(models.Model):
    title = models.CharField(max_length=100)
    guid_url = models.CharField(max_length=255,unique=True, null=True)
    content = models.TextField(validators=[MaxLengthValidator(1200)])
    author = models.ForeignKey(Profile, on_delete=models.CASCADE)
    date_posted = models.DateTimeField(auto_now_add=True)
    last_edited= models.DateTimeField(auto_now=True)
    tags = TaggableManager(help_text="Tags", blank=True)
    likes= models.ManyToManyField(Profile, blank=True, related_name='post_likes')
    
    class Meta:
        indexes = [
            GinIndex(fields=['title','content'],name='search_idx_post')
        ]

I was wondering what is causing this issue I cannot find how to resolve this issue.

Thanks in advance!

4

1 Answer 1

4

Inside the migration file created by Django for adding the GinIndex, add the following:

from django.contrib.postgres.operations import BtreeGinExtension

and then add this to the inside of the operations list, ie:

operations = [
    BtreeGinExtension()
    ...
]

Run this migration again and it should go through.

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

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.