Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
Creating a GIN index in Django

I have created a model in Django.

class MyModel(models.Model):
    features = TextField(blank=True, default='')

There are several possible ways to store the data in the feature field. Some examples below.

  1. feature1;feature2
  2. feature1, feature2
  3. feature1,feature2

And so on. I need to create a GIN index for that field. I would probably do it in postgreSQL in the following way

CREATE INDEX features_search_idx ON "mymodel" USING gin (regexp_split_to_array("mymodel"."features", E'[,;\\s]+'));

Would it be possible to do the same thing by a migration?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Yes.

  • Create an empty migration: python manage.py makemigration yourapp --empty -n pour_gin
  • Add a migrations.RunSQL() operation in the migration file.
class Migration(migrations.Migration):

    dependencies = [
        # ...
    ]
    operations = [
        migrations.RunSQL(
            sql="""CREATE INDEX features_search_idx ON "mymodel" USING gin (regexp_split_to_array("mymodel"."features", E'[,;\\s]+'));""",
            reverse_sql=migrations.RunSQL.noop,  # TODO: replace me with DROP INDEX
        ),
    ]
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda