Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
Crear un índice GIN en Django

He creado un modelo en Django.

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

Hay varias formas posibles de almacenar los datos en el campo de feature . Algunos ejemplos a continuación.

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

Y así. Necesito crear un índice GIN para ese campo. Probablemente lo haría en postgreSQL de la siguiente manera

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

¿Sería posible hacer lo mismo mediante una migración?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Sí.

  • Cree una migración vacía: python manage.py makemigration yourapp --empty -n pour_gin
  • Agregue una operación migrations.RunSQL() en el archivo de migración.
 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!