Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango-hstore on Heroku
    text
    copied!<p>I've got a Django (v 1.3.3) project deployed on Heroku (cedar stack). It uses the recommended dj_database_url for configuring settings.DATABASES. Everything works great (to this point).</p> <p>However, I want to start using <a href="https://github.com/jordanm/django-hstore" rel="nofollow">django-hstore</a> for part of the application. According to the docs, you have to change the database engine in settings.py to: </p> <pre><code>'ENGINE': 'django_hstore.postgresql_psycopg2', </code></pre> <p>As a result, in my settings.py file, I do the following:</p> <pre><code>DATABASES = {'default': dj_database_url.config()} DATABASES['default']['ENGINE'] = 'django_hstore.postgresql_psycopg2' </code></pre> <p>Everything works fine for me, locally. And my models that have hstore fields work great (values are dictionaries).</p> <p>However, when I deploy to Heroku, the database engine gets reset/overridden to:</p> <pre><code>ENGINE: 'django.db.backends.postgresql_psycopg2' </code></pre> <p>In an attempt at debugging it, I have put a print after setting the engine in my settings file. Then, I run bash:</p> <pre><code>heroku run bash </code></pre> <p>and then:</p> <pre><code>python myapp/manage.py shell </code></pre> <p>when I run this, my print statement shows me the correct (desired) database settings with the desired engine (django_hstore.postgresql_psycopg2). However, if I then do:</p> <pre><code>from django.conf import settings print settings.DATABASES </code></pre> <p>I can see the database engine is no longer django_hstore, but set back to the normal (non-hstore) value. And if I import one of my models and do a get to load an object, the value in the hstore field is a string, and any attempt to access a key will throw and error:</p> <pre><code>TypeError: string indices must be integers, not str </code></pre> <p>Please keep in mind that this works find locally. But, after deploying to heroku, any attempt at accessing values as dictionaries throws the TypeError above.</p> <p>My questions are:</p> <ul> <li>Does anyone know why my engine is getting overridden? And if so, how do I fix this?</li> </ul> <p>or</p> <ul> <li>Is there another way to use the hstore field with Django 1.3.3 that might not require having to change the engine (and therefore be a bit more Heroku friendly)</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload