Why does the earth have a magnetic field?
The deflection of the magnetic field is caused due to the solar wind caused by the Sun and prevents the entry of these solar winds into our atmosphere. If the magnetic field is removed from the Earth, then these solar winds could destroy the whole earth and life would not exist on Earth. This is why the earth requires a magnetic field.