Flask-Migrate hangs on table modificiation

Viewed 4183

I have an issue on running the upgrade command with Flask-Migrate. Originally I was trying to modify three tables at once and it hung, I narrowed it down to a specific table (the other upgrades worked without issue). I don't see any locks on the database. I'm using Postgres and just working in a development environment at the moment. The migrate command seems to work fine and generates the upgrade method without any issues (see code)

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('equipment', 'criteria_notes')
    # ### end Alembic commands ###

Once I run the upgrade command I get stuck here:

>flask db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade 76bf72d8e0e4 -> 1723c01f0606, empty message

with a blinking cursor. When I exit out of the command window (I'm using windows) no changes have been applied.

I've tried

  • Restarting computer
  • Looking for locks or other sessions with pgAdmin
  • Modifying other tables, was able to add and drop columns
4 Answers

You likely have other processes connected to this DB.

This happened to me, I had celery, uwsgi, and a separate custom process all connected to the flask DB on a production server, and I was wonder why the upgrades were hanging.

Once I shut these processes down manually the upgrade script ran fine without hanging.

In my case I also tried rebooting before realizing this, and this did not help because these other processes were programmed to startup on boot.

I had this same issue with MySql due to locks and this command did the trick for me.

sudo service mysql restart

I had the same issue, this one happened to me because of locks,verify it using

select * from pg_locks; 

There were many PIDs corresponding to each lock,I restarted the postgresql service then ran the upgrade command it worked

sudo systemctl restart postgresql
flask db upgrade

In my case it was due to locks on the table.

select * from pg_locks; 

in postgres showed me what was happening.

Related