Search code examples
djangopostgresqlhstoredjango-tests

How to resolve a Django hstore error in tests


At some points in the app I'm collaborating on, a HStoreField is used (from django.contrib.postgres.fields). The app itself works normally, no build errors. But when I run tests, I get an issue:

django.db.utils.ProgrammingError: type "hstore" does not exist

From what I found, the issue is with Postgres, so I tried running the following command in psql: create extension hstore; on the template1 database. The extension now shows when listing extensions (\dx):

hstore  | 1.5     | public     | data type for storing sets of (key, value) pairs

Since the error is still here, this obviously wasn't the solution. What should I try?

EDIT: I ran create extension hstore; on the default database from the settings file, too, verified it's created, but still get the same issue.


Solution

  • I figured out what the issue was when I opened up pdAdmin to take a better look. In my settings file, I have a default database, mydb. I ran create extension hstore; in psql on that database, but what I missed was that a new db was created for the tests: test_mydb. I connected to that db and ran the same command there, after which the tests started working.