Search code examples
pythondjangopostgresqlherokuheroku-postgres

Heroku django manage shell with environment setup (db, vars)


I'm trying to get to the django shell so that I can set some superuser permissions for our staff accounts. Doing this by ssh tunneling via ps:exec

We just moved over to heroku, and are using their auto-configured (read: automagical black box) module import django_heroku; django_heroku.settings(locals()) to set database settings.

When I open the shell, those config settings aren't run, and I get an error saying that django.db.utils.OperationalError: no such table: user

Basically, I can't get the shell instance to use Heroku's nice postgres configurer. Any ideas? Workarounds to manually query accounts and set some params? I've tried to import that same magical module from Heroku as part of the shell and instantiate it, but it only works when run in the settings.py file.

I'm trying to not actually log into the postgres instance so that I don't have to open any IP ranges, etc.

__________edit_________

On a similar note, it looks like the shell also can't load Heroku's env vars... getting some issues there as well. Is there a way to run the shell with Heroku's environment completely?


Solution

  • You can access the Django shell through the Heroku Dashboard by using the view console button.

    At the corner there

    So, you can access your shell (Django shell) or the Linux shell of Heroku directly.