How to install Django pg_trgm by makemigrations?

2.1k views Asked by At

I have a Django app and a Postgresql database (in production). Now I want to intall pg_trgm extension for Postgres. But I can't find any step-by-step instructions for installing it from Django app. I have a superuser status. How to do it correctly?

1

There are 1 answers

7
Allen Shaw On
  1. add 'django.contrib.postgres' in your INSTALLED_APPS

  2. add a customer migration file in the app's migration folder. (The migration files are indexed, It's better to follow that index. e.g. 0044_customer_migrations.py)

  3. add TrigramExtension in your migration file

    from django.contrib.postgres.operations import TrigramExtension
    
    class Migration(migrations.Migration):
        dependencies = [
            ('myapp', '0043_latest_migrations'),
        ]
    
        operations = [
            TrigramExtension(),
        ]
    
  4. run migrate

    python manage.py migrate