German Chancellor Angela Merkel said on Saturday that putting up walls will not solve problems caused by immigration, challenging one of U.S. President Donald Trump's core principles, during her visit to Mexico.

Trump's election pledge to build a massive wall on the U.S. border with Mexico to keep out illegal immigrants and drug traffickers has sparked anger throughout Mexico, plunging U.S.-Mexican relations to their lowest point in years.

Speaking in Mexico City, Merkel, who grew up in Communist East Germany behind the Iron Curtain, said that history showed that only when empires have got on well with their neighbours have migration pressures been resolved successfully.

"Obviously the main reason for people leaving must be addressed on site first, which means putting up walls and cutting oneself off will not solve the problem," said Merkel, who has come under political pressure at home for opening German borders to more than one million refugees since 2015.