Flask-Migrate doesn't finish flask db upgrade

Overview

I will explain the solution when the processing is clogged with the following console output when executing flask db upgrade using Flask-Migrate. In this situation, you cannot exit the process with Ctrl + C, and even if you close the terminal, the changes in the DB schema will not be reflected.

 $ flask db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade 576e5f4a0fe7 -> 2b28fe44cc94, empty message

The cause is probably a clogged process that kills the offending process. It's almost the same, but I'll show you how to solve 4 patterns. Since 2 to 4 have not been verified, it may not be possible to solve it.

Method 1 (kill the process from the terminal)

Kill the process on the terminal. When you execute the ps command, a list of running processes is displayed. You can find the corresponding process in it and kill it with the kill command.

##Examine the process that postgres is running
ps aux | grep postgres
##End the relevant process
kill <<Process ID>> # ex) kill 12345

Method 2 (terminate process from PostgreSQL)

Do it on postgres. You may not be able to terminate the process this way.

##Examine the locked process
SELECT * FROM pg_locks;  #The number in the pid column is the process ID

##End the process
SELECT pg_cancel_backend(Process ID);

Method 3 (restart postgresql)

Method 4 (restart the terminal)

Recommended Posts

Flask-Migrate doesn't finish flask db upgrade
Flask Tutorial # 3 ~ DB Linkage ~