How to create GIN index in Django migration

前端 未结 1 591
攒了一身酷
攒了一身酷 2020-12-17 16:41

In Django, since version 1.11 we have a class for PostgreSQL GinIndex (https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/indexes/). I\'d like to creat

相关标签:
1条回答
  • 2020-12-17 17:03

    Haven't yet had a chance to migrate my old manual CREATE INDEX codes to the new system introduced in 1.11 but my understanding is

    from django.contrib.postgres.indexes import GinIndex
    import django.contrib.postgres.search as pg_search
    
    class EntryLine(models.Model):
        speaker = models.CharField(max_length=512, db_index=True)
        text = models.TextField()
        sv = pg_search.SearchVectorField(null=True) 
        class Meta:
            indexes = [GinIndex(fields=['sv'])]
    

    Is what's required. Raw SQL CREATE INDEX statements need not be used any more

    0 讨论(0)
提交回复
热议问题