Here's my humble explanation, as well as me trying to recall it.
First, all nucleis spin. For some reason it just does. The spin is caused by unpaired protons / neutrons I believe..
Nucleis carry charge (proton is +ve, and neutrons are neutral), and spinning charge creates magnetic field...