4 ms·
So if you're aiming for zero downtime rollbacks with Django, here's how adding a new field to a model might work: 1) Add a Migration that adds the new field,
by jeffasinger 11y ago
So if you're aiming for zero downtime rollbacks with Django, here's how adding a new field to a model might work:
1) Add a Migration that adds the new field, but allows null. Deploy.
2) Add the field to the model. Also make sure it sets it's default on write. Deploy.
3) Execute a background task to set the field to whatever it's default value should be.
4) Add migrations to enforce integrity and add indexes. Deploy.
5) Actually deploy code that needs the new field.
Yes, this is super annoying, no, most people don't do this. Separating out #1 and #2 means you can always roll back all the way to right after #1 without losing any data. An extra, nullable field on a model with no indices on it shouldn't hurt anything.
- micah_chatt 11y agoTotally agree. I've been advocating this for months but the ease/simplicity of simply restarting the server with new code has won out for now.