202125 May

How to Simplify Django Migrations and Deployment

Summary

Suppose youve removed one or more fields from Django models, maybe because youre cleaning up old code and they are no longer needed. In particular, when running tests or serving user requests, that field will no longer access the database. And due to the warnings, if your tests have good coverage, this should help spot any lingering references to the field being removed, so they can be fixed in the new code. Since the column has been changed to be nullable (if it wasnt already), then its okay to update records without specifying a value for the deprecated field. Adding Fields to Django Models can have Similar Pitfalls If the new field is not nullable and has no default value in the database, then once the migration has run, theres a new column in the table, but any old code will not know to provide values for it, and database updates will fail.

Source: Caktusgroup

Classifications

Companies