The source of Earth's magnetic field is the molten iron and metals in the earth's core. The spinning of these liquid metals produces the same effect as electric current in a coil which produces a magnetic field.
Divergent plate boundaries because the separating of the tectonic plates allows for the lava to push its way through the rift and escape to Earth's surface.