I was struggling with this for some time and even posted on the Heroku python forums, but no replies so far. To solve the issue I decided not to run the migration remotely on Heroku, but to run the migration on my development machine and pass the production database address instead. So I do this:
- Sync the development db with production (when using Heroku you can easily do this with heroku pg:pull, you have to drop your local db prior to calling this method though)
- Assuming your models are already updated, run the python app.py db migrate. Important: I started getting the original error on my local too, I figured out I have to be in the exact same directory where my app.py is, otherwise I get the error.
- Review your auto-generated migration scripts
- Upgrade your local db with python app.py db upgrade
- Change the settings for your app to use the production db instead of your local development db and then run python app.py db upgrade again
After some thinking it struck me that this might have been the way this tool was designed to work. Although it still would be nice to be able to run the migrations remotely from Heroku, I'll settle for my solution as it is quicker and does the job.