尝试在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不支持,但没有运气。
在本地,它没有问题,我可以迁移和升级数据库(postgres本地和heroku)。
谢谢
这发生在我身上!以下是我解决问题的方法:
我使用登录了我的dyno
heroku ps:exec
然后我去了我的迁移文件夹,env.py不在那里。
所以我检查了我的.gitignore,显然有一条env*
线。
所以只需删除此行,并在Heroku上提交您的migrations / env.py。
首先尝试初始化它。当我在书中实现这些例子时,我也遇到了这个问题。然后我注意到我错过了初始化。