"on_delete=models.CASCADE" in OneToOne not work as ForeignKey relationship

Thank you so much for replying! Let’s me share more about my context.

I’m creating a signal post_delete that logs the deleted objects to console.

For example:

  • Project P has been deleted.
  • Exporter E of Project P has been deleted.
  • Farm F of Project P has been deleted.

When I tried deleting a project, first two logs worked but the third one throwed an exception DoesNotExist, when it tried to access farm.project.name.

After debugging, I think the root cause is because the order of deletion is Exporter → Project → Farm. The Project was deleted before Farm’s deletion so that the Farm cannot access its Project when it was deleted.

Therefore, I expect the order of deletion should be (Exporter, Farm) Project, and I wonder if we have any simple solution to do that. :pensive_face: