Django REST Framework with ForeignKey on_delete=models.PROTECT

when I try to delete Django model object that is ForeignKey in another model with option on_delete=models.PROTECT, the error returned is the normal Django 500 Exception HTML web page, how to make Django rest frame work return json response with the error, is there a way for DRF to do that by default or it should be customized?


Raising 500 Exception is the expected behavior. You have to customize to have a custom error. You can refer to this similar question