Difference between null=True and on_delete=models.SET_NULL django

I have a field

owner = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)

What is the difference between these two attributes on model field ?


null=True means owner field can be null in the database which means you can make an object of your model that has no owner. on_delete=models.SET_NULL means if the owner of an existing object got deleted set this field for existing object to null.

Leave a Reply

Your email address will not be published. Required fields are marked *