Scientists generally attribute this phenomenon to the geodynamo effect. Here, the convective movement of electrically charged, molten iron in the outer core produces electrical currents ...
A planetary magnetic field is produced by a geodynamo effect deep inside a planet. A planet like Earth has an iron-nickel core that comes in two parts, a solid inner core and a molten outer core.