as masterspace noted NASA has actually given it some thought.
"This new research is coming about due to the application of full plasma physics codes and laboratory experiments. In the future it is quite possible that an inflatable structure(s) can generate a magnetic dipole field at a level of perhaps 1 or 2 Tesla (or 10,000 to 20,000 Gauss) as an active shield against the solar wind."
source: https://phys.org/news/2017-03-nasa-magnetic-shield-mars-atmosphere.amp
It also doesn't completely protect the entire planet just two critical points on the surface.
NASA's idea was an inflatable dipole, i linked the article about it up higher