Django test database requires Postgres Extension enabled

Viewed 538

I have a Django app which requires Postgres' fuzzystrmatch extension to be enabled on the database.

Django's unittest framework creates and destroys a new database. I need this new database to have the extension turned on for testing.

I can use './manage.py test --keepdb' to keep the database and then manually turn on the extension, but this is an ineloquent solution.

Any idea how I can enable this extension programmatically?

1 Answers

Create an empty migration and use the CreateExtension operation:

from django.contrib.postgres.operations import CreateExtension

class Migration(migrations.Migration):
    ...

    operations = [
        CreateExtension(name='fuzzystrmatch'),
        ...
    ] 

Relevant docs

Edit: If that doesn't work, reviewing how Django actually handles those classes internally would be my next suggestion.

Related