Why earths magnetic field reverses?

Sir, Like in outer layer of core we have NIFE.
As earth rotates west to east the layer of earth to rotates and creates a magnetic field that is North to South as per right hand thumb rule.

As mangnetic field reverse periodically
So I have a doubt that how it reverses?.
If it is reversing on basis of earth rotation, then earth have to rotates east to west.