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

Viewed 6168

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

class HospitalStay(models.Model):

    patient = models.ForeignKey(User, on_delete = models.CASCADE)
1 Answers

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

Related