An accurate picture of how free electrons are distributed throughout the Milky Way leads to more reliable distances for pulsars and more accurate maps of the magnetic field distribution in the Milky Way. In this paper we test eight models of the free electron distribution in the Milky Way that have been published previously, and we introduce four additional models that explore the parameter space of possible models further. These new models consist of a simple exponential thick-disc model, and updated versions of the models by Taylor & Cordes and Cordes & Lazio with more extended thick discs. The final model we introduce uses the observed Hα intensity as a proxy for the total electron column density, also known as the dispersion measure (DM). Since accurate maps of Hα intensity are now available, this final model can in theory outperform the other models. We use the latest available data sets of pulsars with accurate distances (through parallax measurements or association with globular clusters) to optimize the parameters in these models. In the process of fitting a new scale height for the thick disc in the model by Cordes & Lazio, we discuss why this thick disc cannot be replaced by the thick disc that Gaensler et al. advocated in a recent paper. In the second part of our paper we test how well the different models can predict the DMs of these pulsars at known distances. We base our test on the ratios between the modelled and observed DMs, rather than on absolute deviations, and we identify systematic deviations between the modelled and observed DMs for the different models. For almost all models the ratio between the predicted and the observed DM cannot be described very well by a Gaussian distribution. We therefore calculate the deviations N between the modelled and observed DMs instead, and compare the cumulative distributions of N for the different models. Almost all models perform well, in that they predict DMs within a factor of 1.5–2 of the observed DMs for about 75 per cent of the lines of sight. This is somewhat surprising since the models we tested range from very simple models that only contain a single exponential thick disc to very complex models like the model by Cordes & Lazio. We show that the model by Taylor & Cordes that we updated with a more extended thick disc consistently performs better than the other models we tested. Finally, we analyse which sightlines have DMs that prove difficult to predict by most models, which indicates the presence of local features in the interstellar medium between us and the pulsar.