Programmatically add a taxonomy term as entity reference in a custom entity I'm really struggling to add a taxonomy_term as an entity reference to a custom entity I've created programmatically.

Here is my configuration based on BaseFieldDefinition (the name of the vocabulary is "specialite":

$fields['speciality_field'] = BaseFieldDefinition::create('entity_reference')
  -&gt;setLabel(t('speciality'))
  -&gt;setRevisionable(TRUE)
  -&gt;setSetting('target_type', 'taxonomy_term')
  &gt;setSetting('handler_settings', ['target_bundles' =&gt; ['specialite' =&gt; 'specialite']])
  -&gt;setSetting('handler', 'default')
  -&gt;setTranslatable(TRUE)
  -&gt;setDisplayOptions('view', array(
    'label' =&gt; 'hidden',
    'type' =&gt; 'author',
    'weight' =&gt; 0,
  ))
  -&gt;setDisplayOptions('form', array(
    'type' =&gt; 'entity_reference_autocomplete',
    'weight' =&gt; 5,
    'settings' =&gt; array(
      'match_operator' =&gt; 'CONTAINS',
      'size' =&gt; '10',
      'autocomplete_type' =&gt; 'tags',
      'placeholder' =&gt; '',
    ),
  ))
  -&gt;setDisplayConfigurable('form', TRUE)
  -&gt;setDisplayConfigurable('view', TRUE);


This piece of code doesn't work, would you please help to find what I am missing, or redirect me to a good documentation explaining different values for handler_settings

Thank you so much.
Well thank you, the answer of 4k4 was very useful.
My problem was that for my field I wanted to reference to a taxonomy term, I had already created it and dropped it directly in the database.
It's seems no to be the right way to do this, so I was having such trouble recreating it.
So unisntalled my module (after removing all the data) , and reinstalled it , and then this piece of code worked perfectly to have a reference to a taxonomy term:

$fields['speciality'] = BaseFieldDefinition::create('entity_reference')
  -&gt;setSetting('target_type', 'taxonomy_term')
  -&gt;setSetting('handler', 'default:taxonomy_term')
  -&gt;setSetting('handler_settings', 
      array(
    'target_bundles' =&gt; array(
     'specialite' =&gt; 'specialite'
    )))
  -&gt;setDisplayOptions('view', array(
    'label' =&gt; 'hidden',
    'type' =&gt; 'author',
    'weight' =&gt; 0,
  ))
  -&gt;setDisplayOptions('form', array(
    'type' =&gt; 'entity_reference_autocomplete',
    'weight' =&gt; 3,
    'settings' =&gt; array(
      'match_operator' =&gt; 'CONTAINS',
      'size' =&gt; '10',
      'autocomplete_type' =&gt; 'tags',
      'placeholder' =&gt; '',
    ),
  ))
  -&gt;setDisplayConfigurable('form', TRUE)
  -&gt;setDisplayConfigurable('view', TRUE);


PS: specialite is my the name of my vocabulary