[Fixed]-Django: 'python manage.py migrate' taking hours (and other weird behavior)

23👍

More often than not this is because there is another SQL client or django server or shell reading/writing to the table that you are trying to modify.

An SQL command that changes a schema cannot be successfully executed while a table is being accessed. Ideally an error message should pop up but what usually happens is that the command just waits for the others to finish.

Once you close all your open shells, and sql clients, the schema change can happen. In the worst case, you might need to temporarily take the site offline too.

👤e4c5

0👍

For me, it didn’t even start! I used docker-compose to run my project and my Dockerfile contained RUN python manage.py migrate. Turned out that I put debugpy code in manage.py and let it wait for the debugger using wait_for_client without pressing debug button in vscode, which took forever.

As per debugpy documentation (Waiting for the client to attach)

Use the debugpy.wait_for_client() function to block program execution until the client is attached.

Here what I was trying to do: How to debug Django in VSCode with autoreload turned on

Leave a comment