Django 1.7 Migration hangs

I have a django migration that I am trying to apply. It gets shallow (it's small, it only adds CharField

to two different models. However, when I run the actual migration, it freezes (no crashes, no success, just sits).

Through googling, I found that other open connections might get bad, so I restarted the DB. However, this database connects to constantly running jobs, and new requests immediately sneak in. However, they are small and the last time I tried to restart. I THINK I was able to complete my migration before anything else. Still nothing.

Are there any other known issues that cause something like this?

+3


source to share


3 answers


At least in PostgreSQL, you cannot modify tables (even if they just add new columns) while there are active transactions. The simplest workaround for this is usually:

  • run the migration script (which will hang)
  • reload the webserver / wsgi container


When you restart your web server, all open transactions will be aborted (assuming you have no background processes that also open transactions), so as soon as transactions lock your table, the migration will complete.

+3


source


I had the same problem today. I found that you can clean up any pending transactions in PostgreSQL using the following SQL, just before executing the transaction:

-- View all the current activity
-- SELECT * FROM pg_stat_activity;

-- terminate other connections (make sure to add your own IP address)
SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE client_addr <> 'YOUR IP HERE'

      



This will terminate any connections that are not yours, which may not be ideal in all circumstances, but works like a charm.

+2


source


It is worth pointing out to future readers that the migration may hang when trying to apply the migration for the wrong CharField size (depends on the database implementation). I was trying to change the CharField to be larger than 255 and it just hangs. Even after completing connections as stated, it won't fix it as a CharField larger than 255 as it was wrong with my implementation (postgresql).

TL; DR; ... Make sure your CharField is 255 or less, if more change CharField to TextField and that might solve your problem!

0


source







All Articles