Any human migration tends to have two aspects. These are "push" aspects and "pull" aspects.
In the case of migration from farm to city, the main push aspect was the increased mechanization of farming. Farming no longer needed as many laborers and so there was less work in rural areas. This pushed people away from farms.
There were two pull factors. First, the cities were where the jobs were. Second, the cities were more glamorous and would have seemed like a better and more interesting place to live. These factors pulled people towards cities.