Recently, the signs of both superconducting transition temperature (T c ) beyond 60 K and spin density wave (SDW) have been observed in FeSe thin film on SrTiO 3 (STO) substrate, which suggests a strong interplay between superconductivity and magnetism. With the first-principles calculations, we find that the substrate-induced tensile strain tends to stabilize the SDW state in FeSe thin film by enhancing of the next-nearest-neighbor superexchange antiferromagnetic interaction bridged through Se atoms. On the other hand, we find that when there are oxygen vacancies in the substrate, the significant charge transfer from the substrate to the first FeSe layer would suppress the magnetic order there, and thus the high-temperature superconductivity could occur.In addition, the stability of the SDW is lowered when FeSe is on a defect-free STO substrate due to the redistribution of charges among the Fe 3d-orbitals. Our results provide a comprehensive microscopic explanation for the recent experimental findings, and build a foundation for the further exploration of the superconductivity and magnetism in this novel superconducting interface.