STUTTGART, Germany — With arson attacks on refugee camps and resistance from Chancellor Angela Merkel’s own political partners, it’s not hard to find doomsayers predicting trouble for German cities absorbing asylum seekers. But in this peaceful and pragmatic city, synonymous with German know-how and corporate giants like Bosch, Porsche and Mercedes, it is possible to glimpse something else: a rosier future.

Here, migration has long been an engine of growth, and integration the bedrock of civic pride. The problems Stuttgart faces are ones that prosperous cities around the globe now share, American ones included: a dearth of affordable housing and the kind of apartments that suit the evolving demographics of the people who occupy them.

The message from Stuttgart is that migrants are needed, even welcome. The challenge is building a city they can live in.

“Boomtowns are integration cities,” said Gari Pavkovic, the son of a Croatian guest worker who arrived here decades ago. Mr. Pavkovic now manages immigration for the city government.