【问题标题】:Alembic error on Heroku: Can't find Python file migrations/env.pyHeroku 上的 Alembic 错误:找不到 Python 文件迁移/env.py
【发布时间】:2018-08-24 04:26:29
【问题描述】:

尝试在 Heroku 上部署 Flask 应用程序,过去可以与其他应用程序完美配合,但现在当我尝试升级数据库时:

>:heroku run python manage.py db upgrade

我收到以下错误:

Traceback (most recent call last):
  File "manage.py", line 121, in <module>
    manager.run()
  File "/app/.heroku/python/lib/python3.6/site-packages/flask_script/__init__.py", line 417, in run
    result = self.handle(argv[0], argv[1:])
  File "/app/.heroku/python/lib/python3.6/site-packages/flask_script/__init__.py", line 386, in handle
    res = handle(*args, **config)
  File "/app/.heroku/python/lib/python3.6/site-packages/flask_script/commands.py", line 216, in __call__
    return self.run(*args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/flask_migrate/__init__.py", line 259, in upgrade
    command.upgrade(config, revision, sql=sql, tag=tag)
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/command.py", line 254, in upgrade
    script.run_env()
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/script/base.py", line 425, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/util/pyfiles.py", line 85, in load_python_file
    raise ImportError("Can't find Python file %s" % path)
ImportError: Can't find Python file migrations/env.py

文件 migrations/env.py 在我的本地机器上,在 git 存储库中:

>: git status migrations\env.py
On branch master
nothing to commit, working tree clean

我在本地使用 python 3.6.3,也尝试在 Heroku 上迁移到 python 3.6.4,因为它说不支持 3.6.3,但没有运气。

在本地,它可以正常工作,我可以迁移和升级数据库(本地和 heroku 上的 postgres)。

谢谢

【问题讨论】:

    标签: python heroku flask migrate alembic


    【解决方案1】:

    这发生在我身上! 这是我解决问题的方法:

    我使用

    登录了我的测功机
    heroku ps:exec
    

    然后我转到我的迁移文件夹,但 env.py 不在那里。

    所以我检查了我的 .gitignore,其中显然有一个 env* 行。

    所以只需删除这一行,然后在 Heroku 上提交您的 migrations/env.py。

    【讨论】:

      【解决方案2】:

      先尝试初始化。我在实现书中的示例时也遇到了这个问题。然后我注意到我错过了初始化。

      【讨论】:

        猜你喜欢
        • 2019-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-27
        • 2020-01-17
        • 2015-04-04
        • 1970-01-01
        • 2014-05-18
        相关资源
        最近更新 更多