Importing existing data and relations

Inside foreach, replace data.name with entity.name. Also, wrap the code with trycatch.