0

Trying to deploy a Flask app on Heroku, used to work perfectly with other apps, but now when I try to upgrade the db with:

>:heroku run python manage.py db upgrade

I get the following error:

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

The file migrations/env.py is there on my local machine, and in the git repository:

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

Locally I work on python 3.6.3, tried also to move to python 3.6.4 on Heroku because it says 3.6.3 is not supported, but with no luck.

Locally, it works without problem, I can migrate and upgrade the DB (postgres both locally and on heroku).

Thanks

Libra
  • 369
  • 4
  • 15

2 Answers2

2

This happened to me ! Here is how I solved the problem:

I logged into my dyno using

heroku ps:exec

Then I went to my migrations folder, and the env.py was not there.

So I checked my .gitignore, and there was obviously a env* line in it.

So just delete this line, and commit your migrations/env.py on Heroku.

ksahin
  • 206
  • 1
  • 7
0

Try to init it first.I also encountered this problem when I implemented the examples in the book.Then I noticed that I had missed initalization.