People have been moving from one country to another as long as there have been countries. Sometimes they were welcomed by the countries they were relocating to. Often they were not. When the migrants were unwelcome, they might encounter hostility upon entry. In certain instances they came anyway. They judged they had more to lose from remaining in their homelands than from the enmity they would encounter in their new lands.
Sometimes they fought their way in. The invasion of the Roman empire by the Goths in the 3rd century and after was partly a migration and partly a military campaign. The flood of Americans into Mexican Texas in the 1820s began as a migration and ended as a war of conquest. From the perspective of American Indians, the westward movement of settlers from the United States was a combined migration and military operation that lasted centuries.
When the migrants arrived without arms the result could be just as unsettling. The 1971 war between India and Pakistan resulted in no small part from the millions of refugees who entered India to escape fighting in East Pakistan between Bengali separatists and government troops. The war ended with the dismemberment of Pakistan and the creation of Bangladesh.
Sometimes the country of origin was the one that took the migration amiss. As the French Revolution descended into its reign of terror in the early 1790s, the wealthy and well connected from the old regime fled for their lives. Some of the emigres went to Austria, some to Prussia, some to Britain. On arrival they emphasized the threat the revolutionary government in Paris posed to their hosts. The French tried to prevent the escape of the emigres and proclaimed their polite reception by the foreign governments an intolerable provocation. Reciprocal recriminations led to a general European war.
Migration can reconfigure governments even short of war. After the Syrian civil war of the 2010s sent waves of refugees west, the ripple effect across the European Union amplified dissatisfaction in Britain with EU policies. A 2016 referendum produced a decision to depart the EU, with Brexiteers commonly identifying immigration as the decisive issue behind their leave votes.
Unwelcome immigration is often likened to invasion. The connection, as noted above, has sometimes been apt. But often it is exaggerated, not least since most immigrants don't bear weapons and aren't organized into military columns. Yet the invasion trope is irresistible to opponents of immigration, who wrap themselves in the banner of patriotism and homeland security. They portray their political rivals as weak, themselves as strong. The formula often works. Voters respond to strength.
Aside from Texas and the expansion into Indian country, migration has never been the primary cause of an American war. Yet migration has often been a consequence of war. After the American Revolution, tens of thousands of Loyalists decamped for Canada, the West Indies and Britain. After the Civil War, thousands of former slaves, including many who had fought on behalf of the Union, left the South for the American West. America's alliance with China during World War II caused Congress to repeal the Chinese Exclusion Act, which had barred the immigration of most Chinese since the 1880s. After the Vietnam war, more than a million migrants left Vietnam for the United States. After the Afghanistan war, some 200,000 Afghans migrated to America.
Migration is as old as humanity. So is war. The coincidence is no accident.