Flask database migrations on heroku
Asked Answered
C

1

10

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?

Calabresi answered 26/9, 2017 at 15:7 Comment(0)
A
21

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.

Amaranthine answered 26/9, 2017 at 15:9 Comment(3)
So to be clear, you create you migrations folder locally and then do migrations/upgrades on heroku?Calabresi
yeah, do heroku local db init then commit the result.Amaranthine
You actually want to do flask db init and flask db migrate locally. Commit the results to your git repo. Then on Heroku, you only do the heroku run flask db upgrade.Coiffure

© 2022 - 2024 — McMap. All rights reserved.