How to make a related field mandatory in Django?
<p>Suppose I have the following many-to-one relationship in Django:</p>

<pre><code>from django.db import models

class Person(models.Model):
    # ...

class Address(models.Model):
    # ...
    person = models.ForeignKey(Person, on_delete=models.CASCADE)
</code></pre>

<p>This allows a person to have multiple addresses.</p>

<p>I wish to make it mandatory for a person to have at least one address, so it will be impossible to save a person with no addresses in the DB.</p>

<p>How can I achieve this goal? Is it possible to make a related field mandatory (as can be done for "normal" fields using <code>blank=False</code>)?</p>

<p>Why not make Address a many to many relationship on Person? That seems to be a more natural expression of your data. </p>

<p>But regardless, you can't really enforce the many to many realation on the db. You could perhaps override the save of Person to check for an address. But I would prefer to handle it in the form logic. </p>

python django django-models relationship