alembic stuck on database upgrade

See original GitHub issue

I’m running a database migration, and Alembic complains with alembic.util.CommandError: Target database is not up to date.

So and I then run a database upgrade python manage.py db upgrade

Here is the output: INFO [alembic.migration] Context impl PostgresqlImpl. INFO [alembic.migration] Will assume transactional DDL. INFO [alembic.migration] Running upgrade 604497a5e5 -> 431e33e6fce, empty message

The issue is that Alembic never finishes the upgrade (never quits the terminal) and it appears stuck on the third step, I have tried severally, even leaving it for several minutes but it never completes the upgrade. I have tried running this locally and on the server and it doesn’t work (it’s not an issue with the connection).

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:12

github_iconTop GitHub Comments

54reactions
jwindridgecommented, Jul 29, 2015

Thanks for the reply - worked it out in the end: I had a database session open in a flask shell, which was preventing alembic from obtaining a lock and therefore running the update - finished the session and then the migration worked fine.

3reactions
kangju1commented, Aug 19, 2019

For those who want to run alembic upgrade when app is running, add the following code in your project’s app file.

@app.teardown_appcontext
    def shutdown_session(exception=None):
        db.remove()

the variable db is the database session from your database setting file. so you should import it first. you have to remove the session (return it to the pool) after each request.

When alembic runs, it uses flask’s app context, and the currently running app is holding all connections, which means there are no available connections for alembic to use.

https://flask.palletsprojects.com/en/1.0.x/appcontext/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Alembic migration stuck with postgresql? - Stack Overflow
your database is most likely locked by another query. Especially if you do stuff with their GUI pgAdmin, this can happen a lot...
Read more >
The process gets stuck in INFO [alembic.migration] Running ...
In most cases, this is due to the fact that you want to update the table that is currently being used by the...
Read more >
How to enable verbosity on “alembic upgrade head”?
n one of the python projects I'm working on we are using alembic to handle the DB migration scripts. Lately he had an...
Read more >
Upgrading PostgreSQL's Enum type with SQLAlchemy using ...
Alembic is an awesome library to setup migrations for your database ... so you don't get stuck with upgrading the enum types yourself...
Read more >
How To Add Flask-Migrate To An Existing Project
It simply sets that Alembic revision that reflects the state of the database. So there's nothing to commit or merge, just run flask...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found