【问题标题】:Heroku: relation does not existHeroku:关系不存在
【发布时间】:2013-08-18 22:06:31
【问题描述】:

我正在使用 Python、Flask 和 Peewee ORM。我的 DATABASE_URL 设置正确。

我已经在本地服务器上测试了该功能,它可以正常工作。当我部署到 Heroku 时,它在 Peewee 在我的应用程序的 if name == main 部分创建的表上出错。

错误是:

ProgrammingError: relation "connection" does not exist (connection 
is the name of my model/would-be table).

更新:我通过在特定路径下的 views.py 文件中创建表来解决问题。这是必要的吗?我更喜欢更清洁的方式。

【问题讨论】:

    标签: python heroku flask peewee


    【解决方案1】:

    我从未使用过 Heroku,但我猜 Heroku 正在以某种方式导入您的应用程序,绕过了仅在直接运行此模块时运行的 if __name__ == "__main__" 块。您应该尝试将逻辑从 if 块移动到 before_first_request 处理程序中,以便它仍然会运行,但只能运行一次(每个工作人员/应用程序实例)

    @app.before_first_request
    def initialize():
        app.logger.info("Creating the tables we need")
        ...
    

    【讨论】:

      猜你喜欢
      • 2015-07-26
      • 2018-12-02
      • 1970-01-01
      • 2018-05-15
      • 2015-02-26
      • 2018-07-16
      • 2019-01-24
      • 2016-11-03
      • 2016-04-11
      相关资源
      最近更新 更多