[Fixed]-Django: How to make admin not delete the relative objects?

1👍

Set the on_delete option for your foreign key. If you you want to set the value to None when the related object is deleted, use SET_NULL:

models.ForeignKey('app.ObjectToDelete', on_delete=models.SET_NULL)

These rules apply however you delete an object, whether you do it in the admin panel or working directly with the Model instance. (But it won’t take effect if you work directly with the underlying database in SQL.)

Leave a comment