The invention relates to a Zn1-xMgxO group heterojunction and a preparation method of the Zn1-xMgxO group heterojunction. The heterojunction is composed of an n-Zn1-xMgxO thin layer and a p-Ni1-yMgyO thin layer which are positioned on a substrate. The preparation method includes the following steps: (1) mixing ZnO and MgO with Al2O3 powder or Ga2Ob powder, compression molding and sintering the mixture, and obtaining Zn1-xMgxO ceramic target material mixed with Al or Ga, (2) mixing NiO, MgO and Li2CO3 powder, compression molding and sintering the mixture, and obtaining Li1-xMgxO ceramic target material mixed with Li, (3) putting the substrate in a pulsed laser deposition device, adjusting the distance between the target materials and the substrate, depositing the n-Zn1-xMgxO thin layer on the substrate using the Ni1-xMgxO ceramic target as sputtering target material under proper substrate temperature, oxygen pressure and laser frequency, (4) depositing the p-Ni1-yMgyO thin layer on the n-Zn1-xMgxO thin layer using the Ni1-xMgxO ceramic target mixed with Li as sputtering target material, and obtaining the Zn1-xMgxO group heterojunction. The Zn1-xMgxO group heterojunction preparation method has the advantages that preparation method is simple, cost is low, producing conditions are easy to control, compatibility of interface lattices is good, and performance of components is improved. Further, the Zn1-xMgxO group heterojunction has a wide application prospect in short wave optoelectronic devices and transparent electronics field.