Your Notification
model has a ForeignKey
relation to your user model. So a single user model instance can have multiple Notification
instances associated with it. What on_delete
means (what django is asking of you) is that if you delete an instance of your user model what should django do with all the associated Notification
instances?
From django 2.x
this argument became required.
Please read up on this to see all the options. But a quick rundown.
If you want all associated Notification
instances to be deleted when you delete an instance of user model, set on_delete=models.CASCADE
.
recipient = models.ForeignKey(settings.AUTH_USER_MODEL, blank=False, related_name='notifications', on_delete=models.CASCADE)
If you want the notification to remain untouched when you delete an instance of a user model, use on_delete=models.SET_NULL
. But in this case you will have to set null=True
on the recipient field. The notification will remain but it will not belong to any user.
recipient = models.ForeignKey(settings.AUTH_USER_MODEL, blank=False, related_name='notifications', on_delete=models.SET_NULL, null=True)