Bird
0
0

In a production environment, you want to add a new non-nullable field to a large existing table without downtime. Which approach is safest?

hard📝 Application Q15 of 15
Django - Deployment and Production
In a production environment, you want to add a new non-nullable field to a large existing table without downtime. Which approach is safest?
AAdd the field as non-nullable directly and run migrate
BSkip migrations and add the field manually in the database
CDrop the table and recreate it with the new field
DAdd the field with <code>null=True</code>, migrate, then update data and alter to <code>null=False</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand downtime risks

    Adding a non-nullable field directly can lock the table and cause downtime in production.
  2. Step 2: Use a two-step migration

    First add the field as nullable (null=True), migrate, then fill data, and finally alter to non-nullable (null=False).
  3. Final Answer:

    Add the field with null=True, migrate, then update data and alter to null=False -> Option D
  4. Quick Check:

    Two-step migration avoids downtime = B [OK]
Quick Trick: Add nullable field first, then make non-nullable after data update [OK]
Common Mistakes:
MISTAKES
  • Adding non-nullable field directly causing downtime
  • Dropping tables losing data
  • Skipping migrations causing inconsistencies

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes