How to programmatically associate a taxonomy term to a field I'm trying to import user profiles data from a JSON file. Several fields are entity reference to vocabularies. 
I'm able to create a new taxonomy term entity in the universities vocabulary bundle using the following code:
$term = Term::create([
  'name' =&gt; &quot;University of Bologna&quot;, 
  'vid' =&gt; 'universities',
])-&gt;save();

Now I have to link this newly created term to a field contained in Profile Type. I'm testing the following code.
    $values = array(
        'type' =&gt; 'profile_type',
        'uid' =&gt; 3043,
    );
    $profileStorage = \Drupal::entityTypeManager()-&gt;getStorage('profile');
    $profileEntity = $profileStorage-&gt;create($values);
    $profileEntity-&gt;field_entry_university-&gt;appendItem($term);
    $profileEntity-&gt;save();

However, this approach doesn't work. How can I fix it?
appendItem takes an array.
Try $profileEntity-&gt;field_entry_university-&gt;appendItem(['target_id' =&gt; $term-&gt;id());