问题
With my app I am using flask-script and flask-migrate for database migrations, everything works locally. When, I run
heroku run python manage.py db init
It creates this output:
Running python manage.py db init on ⬢ fpds-scheduler... up, run.1290 (Free)
Creating directory /app/migrations ... done
Creating directory /app/migrations/versions ... done
Generating /app/migrations/README ... done
Generating /app/migrations/script.py.mako ... done
Generating /app/migrations/alembic.ini ... done
Generating /app/migrations/env.py ... done
Please edit configuration/connection/logging settings in '/app/migrations/alembic.ini' before
proceeding.
But when I run heroku run python manage.py db migrate
I get an error
alembic.util.exc.CommandError: Path doesn't exist: 'migrations'. Please use the 'init' command to create a new scripts folder.
When I run heroku run bash
and look at my directory I can see that there is no migrations
folder...
I have tried running giving the command --app fpds-scheduler
but that doesn't seem to be working either.
I am not sure what is going wrong?
回答1:
You must not create the migrations on Heroku itself. The filesystem is ephemeral and anything written programatically will be lost between invocations.
You need to create the migrations locally, commit them to version control, deploy, and only then run them on Heroku.
来源:https://stackoverflow.com/questions/46430061/flask-database-migrations-on-heroku