Trump's election pledge to build a massive wall on the US border with Mexico to keep out illegal immigrants and drug traffickers has sparked anger throughout Mexico, plunging US-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 neighbors 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.
"It's an issue you can study well in the history of China with the (Great) Wall of China, you can study it in the history of the Roman Empire. Essentially, only when great empires have managed to forge sensible relationships with their neighbors and to manage migration has it been a success," she added.
"I don't think that by simply improving the border facilities you can solve the problem," she told a panel discussion alongside Mexican President Enrique Pena Nieto.
The key was to improve living standards and opportunities in afflicted areas, said Merkel, who did not mention Trump.
Trump has backed away from a promise to make Mexico pay for the wall and has had to pare back his ambitions in seeking funds to build the barrier from the US Congress, where Democrats and even some Republicans have criticized the plan.
In another counterpoint to Trump, Merkel and Pena Nieto together affirmed their commitment to free trade during the German leader's visit to Latin America's No. 2 economy.
Pena Nieto said Mexico will ensure that foreign investment in Mexico remains protected in talks sought by Trump to renegotiate the North American Free Trade Agreement (NAFTA).
Trump has attacked Germany and Mexico for their trade surpluses with the United States and has vowed to withdraw from NAFTA if he cannot renegotiate it in favor of the United States.
Germany has made major investments in both Mexico and the United States, and Merkel said it was important not to forget the benefits that international trade had brought.
"Through (international supply chains), wealth for a lot more people has been generated, and these value chains should not be destroyed again unnecessarily," Merkel said.
(Reporting by Dave Graham and Andreas Rinke; Additonal reporting by Stefanie Eschenbacher; Editing by Chizu Nomiyama and Bill Rigby)
(Except for the headline, this story has not been edited by NDTV staff and is published from a syndicated feed.)