It contains two solutions, one simple but brittle and a second one more advanced but with stronger guarantees.
Sorry. I tried the first one. But the Farm still was deleted after the deletion of the Project, so the exception was still thrown.
I’ve just tried remove null=True, and it’s worked! So now I think declaring that column as nullable may cause Django to perform deletions in a random order, while not allowing null will ensure that the parent object is always deleted afterward.