Running Django migrations in a multi-container Docker setup Running Django migrations in a multi-container Docker setup docker docker

Running Django migrations in a multi-container Docker setup


No, it's not safe to run the migration in all containers at the same time, since you might end up applying the same migration twice.

There are two possible cases:

  1. Applying the migration twice (e.g. adding a table column) violates a database constraint, so therefore only the first container that run the migration manages to finish the migration. In this case the other containers will die, although your orchestration system probably will restart them.

  2. Applying the migration twice doesn't violate any constraint and therefore can be applied multiple times. In this case you can end up with duplicated data.

In any case, you should try to have only one container applying migrations at the same time.