What user34296 said is update_post_meta()
will update the value of the existing meta key (custom field) for the specified post. If it does not already exist it will call add_post_meta($post_id, $meta_key, $meta_value)
instead. That’s why you should use it.
EDIT: in this case it should work, error is coming from another part of the code.