Dynamo theory suggest how magnetic field generated on Earth. Due to flowing magma which contains molten iron generates magnetic field on earth. But how magnetic field is generated over sun?
The Sun's interior is partly or completely ionised and therefore supports the flow of electric currents. The solar magnetic field is explained by a solar dynamo that converts the kinetic energy of electrically charged fluid flows in the Sun (due to differential rotation and convection) into electromagnetic energy.