You're trying to add a row that already exists, so it fails, which causes the entire XML to be discarded, which means the unit doesn't exist in the database when you come to reference it from the Civilization_UnitClassOverrides table, hence the error.
"Invalid reference" ... "something I was...