Heroku django 通过环境设置(db、vars)管理 shell

dst*_*r77 4 python django postgresql heroku heroku-postgres

我正在尝试访问 django shell,以便为我们的员工帐户设置一些超级用户权限。通过 ssh 隧道来完成此操作ps:exec

我们刚刚转移到 Heroku,并使用他们的自动配置(阅读:自动魔法黑盒)模块import django_heroku; django_heroku.settings(locals())来设置数据库设置。

当我打开 shell 时,这些配置设置不会运行,并且收到一条错误消息 django.db.utils.OperationalError: no such table: user

基本上,我无法让 shell 实例使用 Heroku 漂亮的 postgres 配置器。有任何想法吗?手动查询帐户并设置一些参数的解决方法?我尝试从 Heroku 导入相同的神奇模块作为 shell 的一部分并实例化它,但它仅在 settings.py 文件中运行时才有效。

我试图不实际登录 postgres 实例,这样我就不必打开任何 IP 范围等。

__________编辑_________

类似地,看起来 shell 也无法加载 Heroku 的环境变量......在那里也遇到了一些问题。有没有办法完全在Heroku的环境下运行shell?

Ste*_*dge 5

您可以python manage.py shell直接通过heroku cli运行:

heroku run python manage.py shell --app=your-app-name
Run Code Online (Sandbox Code Playgroud)