Django FK on_delete defaults to CASCADE

What does this mean!? Well, lets make an example.

class Company(models.Model):
name = models.CharField(max_length=100)
logo = models.ForeignKey(File, null=True, blank=True)
class File(models.Model):
filename = models.CharField(max_length=100)
mime = models.CharField(max_length=100)

Say we have an Company object and a File object. The file object is set to be the logo.

company = models.Company.objects.create(name='A Company')
file = models.File.objects.create(filename='file.jpg', mime='jpeg')
company.logo = file
company.save()

If we then delete the file

file.delete()

Then we will actually also delete the company object because by default django will, on delete, cascade. So, we have to set the on_delete attribute to avoid this.

class Company(models.Model)
name = models.CharField(max_length=100)
logo = models.ForeignKey(File, null=True, blank=True, on_delete=models.SET_NULL)

If the File object is deleted nowm the logo will be set to NULL rather than deleting the object.