After joining p-type and n-type semiconductors, electrons from the n-region near the p-n interface tend to diffuse into the p-region. As electrons diffuse, they leave positively charged ions (donors) in the n-region. Likewise, holes from the p-type region near the p-n interface begin to diffuse into the n-type region, leaving fixed ions (acceptors) with negative charge.
Thus, an electric field is established at the junction directed from the n-type side to the p-type side.