What are the on_delete options for a ForeignKey (CASCADE, PROTECT, SET_NULL, etc.), and how do you decide which to use?

Last updated 17 June 2026

  • on_delete (required) defines what happens to referencing rows when the target is deleted: CASCADE deletes them, PROTECT blocks the delete with ProtectedError, and SET_NULL nulls the FK (needs null=True).

  • SET_DEFAULT / SET(...) reassign to a default or sentinel value. DO_NOTHING leaves integrity to the database.

  • Decide by meaning: child can't exist without parent means CASCADE. Child survives orphaned means SET_NULL. Data must never be lost means PROTECT.

  • https://www.geeksforgeeks.org/python/onetoonefield-vs-foreignkey-in-django/
All Django interview questions