Entityreference not saved correctly inside ContentEntityForm
Found the cause!

Someone had added the line

$this-&gt;getReferencedEntity();


to the MainEntity::__construct()-method.

getReferencedEntity()-method uses some database-magic to find the reference and then set it to the MainEntity. 

This worked fine before Drupal 8.5 but it seems that after that the system thought it already had the reference and didn't bother to insert it to the database.