Django prevent cascading delete

I accidentally deleted tons of data with a quick `Contact.objects.all().delete()`

Remember that any model that references the instance in question, even if the `ForeignKey` is nullable, will be deleted by django.

Use the on_delete argument on ForeignKey definition to prevent this behavior.

In my case, I had a large core model referencing a not-so-important stand alone model which was deleted. Important things shouldn’t be deleted just because they happen to reference an unimportant thing 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s