How do I set an entity base field as NOT NULL? When creating custom entities in Drupal 8, you define a bunch of fields in baseFieldDefinitions() on your entity class, like this:

  &lt;?php
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);

    $fields['postal_code'] = BaseFieldDefinition::create('integer')
      -&gt;setLabel('PLZ')
      -&gt;setDescription(t('Postal code.'))
      -&gt;setSetting('unsigned', TRUE)
      -&gt;setDisplayOptions('form', [
        'type' =&gt; 'number',
      ])
      -&gt;setRequired(TRUE);

    return $fields;
  }


However, these fields, despite being marked required, are defined as nullable in the database.

There’s no -&gt;setNullable(FALSE) or similar method on BaseFieldDefinition. So how else do you make Drupal generate the schema correctly?
There is no API for that at the moment, every field that is specified as a key happens to be set to not null, but that's IMHO actually a bug and I would not rely on that.

Instead, the only thing you can do is provide a storage schema handler and customize the schema there.

See \Drupal\node\NodeStorageSchema::getSharedTableFieldSchema() for example.