The admin interface isn't letting me leave a set empty

I am looking to make a tree. Each human can have any number of parents and any number of children.

From the command line, I can make arbitrary trees.

But when I use default the web admin interface,

  • it won’t let me create a childless human
  • it won’t let me delete the last child

It complains

This field is required.

How do I fix this?

from django.db import models

class Human(models.Model):
    name = models.CharField('Person', max_length=200)
    sons = models.ManyToManyField('self', symmetrical=False,
                                  related_name='fathers')

    def __str__(self):
        return self.name

It looks like you might be missing blank on your model definition. blank is used by auto-generated forms (like in the Django admin) to determine if a field is required or not. https://docs.djangoproject.com/en/3.0/ref/models/fields/#blank

Thank you.

Adding


      blank=True, null=True,

has fixed it.

The

    null=True

generated a warning

(fields.W340) null has no effect on ManyToManyField.

removing it and keeping just the

    blank=True

maintained the desired behavior.