When I try running heroku run flask db upgrade to upgrade my Heroku PostgreSQL db, I get the error FileNotFoundError: [Errno 2] No such file or directory: '/app/migrations/versions' error in flask migrate Heroku app. I have a migrations folder in the root directory. flask db init now returns error that the migrations directory is already created and populated. flask db migrate seems to be working fine.
Dircetory Schema Local:
migrations
- versions
- alembic.ini
- env.py
- script.py.mako
app-directory
- static
- templates
- __init__.py
- forms.py
- models.py
- routes.py
manage.py
run.py
Procfile
run.py
from app-directory import app, db
if __name__ == '__main__':
app.run()
__init__.py
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
...
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
if __name__ == '__main__':
manager.run()
manage.py
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
if __name__ == '__main__':
manager.run()
I can update the db using db.drop_all() but that deletes all the data in the Heroku PostgreSQL database, and I don't want to do that.
#####EDIT#####
When checking heroku run bash, I ran heroku run flask db upgrade with and without migrations directory in the heroku run bash command prompt and it still doesn't work. I tried following this https://stackoverflow.com/questions/46430061/flask-database-migrations-on-heroku but it doesn't help.
In addition, this is my Procfile:
web: gunicorn --bind 0.0.0.0:$PORT run:app
Another update, when I check heroku run bash, the migration directory DOES NOT have the versions directory, which is obviously the problem. However, the versions directory is local computer and I am pushing it up to heroku master with:
git add -A
git commit -m"message"
git push heroku master
All the other files in the migrations directory is in the heroku bash but not the versions directory.
Do you have your migrations directory and all of its contents under source control?
It was. I ended up deleting and recreating the Heroku app and now it works perfectly.
I had the same issue! The problem is that /versions doesn't exist. So I just put an empty ".keep" file in my versions folder, and pushed to heroku. db migrate, db upgrade, etc should work from there. Hope this is helpful to other people with the same issue
Most helpful comment
I had the same issue! The problem is that /versions doesn't exist. So I just put an empty ".keep" file in my versions folder, and pushed to heroku. db migrate, db upgrade, etc should work from there. Hope this is helpful to other people with the same issue