4

what happens when we use "on_delete=models.CASCADE" in django models

class HospitalStay(models.Model):

    patient = models.ForeignKey(User, on_delete = models.CASCADE)
Karthik Sai
  • 87
  • 1
  • 4
  • 5
    What is unclear about [the documentation](https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.CASCADE) for that option? – Daniel Roseman Jan 17 '19 at 09:58

1 Answers1

16

CASCADE means that the row will be deleted too if the ForeignKey gets deleted.

In your case, HospitalStay instance will be deleted if the User Linked to it gets deleted.

Read more on django docs

Navid Zarepak
  • 4,148
  • 1
  • 12
  • 26