Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask database migrations on heroku

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?

like image 505
spitfiredd Avatar asked Sep 26 '17 15:09

spitfiredd


1 Answers

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.

like image 90
Daniel Roseman Avatar answered Sep 23 '22 19:09

Daniel Roseman