How to set parent on taxonomy term
The correct way for a reference field is to set the property target_id:

$term-&gt;parent = ['target_id' =&gt; '2'];


All this shorter versions work too:

$term-&gt;parent = ['2'];
$term-&gt;parent = '2';
$term-&gt;parent = 2;


Also works like this:

$term-&gt;set('parent', ['target_id' =&gt; 2]);
$term-&gt;set('parent', 2);