They are also getting votes from the ederly who see their villages and small towns slowly dieing (no shops, no doctors, no shools, etc.), because the youth moves away to see any perspective. They get votes from workers, who do worthwile work, work that perhaps doesn´t take an university degree, but is essential for our society to function and make life for all more comfortable, but are extremely poorly payed and forces them to receive money from the state. They get votes from people having trouble to find apartments as rents are exploding in the cities.
For the most part, they get votes from the people that don´t feel heard and be left alone by the government, so they latch onto the loudest voice that opposes the government. They don´t vote for the AfD because they share their views or stand behind their programm, the statistics are clear on that. Most don´t even want them in power, but an actual opposition who challenges the government.
Don´t get me wrong, voting the AfD is horribly short sighted but desperation tends to have such effect.
Ironically the result that came from their voting is that the social democrates are forced to go into oppositon and have to reinvent themelves to regain their voter base. Maybe they will be wise to actually listen to these people then and give them believable options to make their lives a little bit better. Maybe they learn a thing or two in the process, aswell.