Magnetic and transport properties of 10 wt% SiC doped MgB2 and 5 wt% nano-C doped MgB2 were studied by resistance and critical current density measurements. The results showed improvement of the critical current density for the MgB2 superconductor doped with SiC in comparison with the nano-C doped sample. The flux pinning mechanisms of both doped MgB2 superconductors have been investigated based on the collective theory. It was found that the pinning mechanism in MgB2 was transformed by SiC doping from transition temperature fluctuation induced pinning, δTc pinning, to mean free path fluctuation induced pinning, δℓ pinning, while in the MgB2 doped with nano-C, δTc and δℓ pinning coexist. Their contributions are strongly temperature dependent, however. The δℓ pinning is dominant at low temperature, decreases with increasing temperature, and is suppressed completely at temperatures close to Tc. The δTc pinning mechanism shows the opposite trend.