2

I'm using HstoreField in one of my models and when I try to test it I got an error psycopg2.ProgrammingError: ERROR: function hstore(integer[], text[]) does not exist. If I understand this problem correctly it happend because hstore extension wasn't setup in database as it was did in migrations by adding HStoreExtension operation (documentation).

How to setup hstore extension in default test database and solve my problem?

DiA
  • 257
  • 4
  • 16
  • Do you have a migration that sets up the extension? Do you have the dependenies so that it runs before any migrations that create an `HStoreField`? – Alasdair May 13 '16 at 08:52
  • @Alasdair Yes, hstore extension was setted in 12th app's migration file of 15 and everything working fine but tests. And I'm sorry but I didn't understand the second quesion, what do you mean under dependencies? – DiA May 13 '16 at 09:04
  • I'll try to explain differently. One (or more) of your models uses `HStoreField`. If the migration that creates the first `HStoreField` is migration 13 or more, that's ok because the extension is installed in migration 12. If, say migration 10 creates the first `HStoreField`, then you have a problem, because the extension isn't installed by that point. – Alasdair May 13 '16 at 09:07
  • @Alasdair Oh, ok, I understand. Extension installation and first `HStoreField` are in the same migration file, but installation operation was called before creating first `HStoreField`. – DiA May 13 '16 at 09:13
  • You could try moving the extension installation into an earlier migration. – Alasdair May 13 '16 at 09:20
  • @Alasdair No effect( – DiA May 14 '16 at 13:56
  • Sorry, I don't have any other suggestions. Hope you manage to figure out the problem. – Alasdair May 14 '16 at 17:35
  • @Alasdair Thank you anyway) – DiA May 15 '16 at 03:05

1 Answers1

2

Thanks to Simon Charette, who answer this question in django-users:

From the exception it looks like the issue is not related to a missing extension but from an attempt of using and integer as a key. e.g.

instance.hstore_field = {1: 'foo'} instead of instance.hstore_field = {'1': 'foo'}

Keys and values in hstore in postgresql are simply text strings (docs) and Django don't convert key object into string. So my HStoreExtension assumption was the wrong way...

Community
  • 1
  • 1
DiA
  • 257
  • 4
  • 16