PDOException when setting field value in node presave
Sounds like you should be setting target_id instead:

foreach ($nameResult as $row) {
  $node-&gt;field_co_pi[LANGUAGE_NONE][$i]['target_id'] = intval($row-&gt;entity_id);
}


Note that not all fields have the same data column (such as 'value'). Reference fields have target_id which holds the referenced entity id.

Aside from that, just make sure that it has a value before setting, or you will get the same error again.

You redacted other parts of the code, so, I can't see if you set $i or not. Are you incrementing that per loop with $i++? I just assumed it is a multivalued field since you are doing a foreach instead of setting [0] directly.