Search code examples
djangodjango-rest-frameworkdjango-testing

Django test with pgcrypto failing


I'm using a PostgreSQL database for my Django app with pgcryto extension installed. On the production server I manually create a user and then run CREATE EXTENSION pgcrypto; in order to install the extension.

However when I run ./manage.py test it fails because my models are using the EncryptedTextField field from pgcrypto_expressions, the test database that's automatically created does not have the extension installed naturally (since it needs to be enabled explicitly for every database created). How can I 'inject' code / commands between the time Django sets up my test database and begins migrations?

Or rather, how can I enable this extension globally in PostgreSQL?


Solution

  • With help primarily from @Alasdair, I was able to setup a dummy app that sits between my app and the rest. I was then able to tweak my dependencies such that the build-server continues to clean up migrations in the real app, while always installing the pgcrypto extension before my app is migrated.