By 1846, war was nearly inevitable between the USA and Mexico.
Meanwhile, tensions were high on the Texas/Mexico border. In 1842, Santa Anna sent a small army to attack San Antonio: the Texas responded by attacking Santa Fe.
Meanwhile, the USA had its eye on Mexico's northwestern possessions, such as California and New Mexico. The Americans wanted more land and believed that their country should stretch from the Atlantic to the Pacific. The belief that America should expand to fill the continent was called "Manifest Destiny." This philosophy was expansionist and racist: its proponents believed that the "noble and industrious" Americans deserved those lands more than the "degenerate" Mexicans and Native Americans who lived there.
The USA tried on a couple of occasions to purchase those lands from Mexico, and was rebuffed every time. President James K. Polk, however, would not take no for an answer: he meant to have California and Mexico's other western territories and he would go to war to have them.
Fortunately for Polk, the border of Texas was still in question: Mexico claimed it was the Nueces River while the Americans claimed it was the Rio Grande. In early 1846, both sides sent armies to the border: by then, both nations were looking for an excuse to fight. It wasn't long before a series of small skirmishes bloomed into war. The worst of the incidents was the so-called "Thornton Affair" of April 25, 1846 in which a squad of American cavalrymen under the command of Captain Seth Thornton was attacked by a much larger Mexican force: 16 Americans were killed. Because the Mexicans were in contested territory, President Polk was able to ask for a declaration of war because Mexico had "…shed American blood upon the American soil." Larger battles followed within two weeks and both nations had declared war on one another by May 13.
The war would last about two years, until spring of 1848. The Mexicans and Americans would fight about ten major battles, and the Americans would win all of them. In the end, the Americans would capture and occupy Mexico City and dictate terms of the peace agreement to Mexico. Polk got his lands: according to the Treaty of Guadalupe Hidalgo, formalized in May of 1848, Mexico would hand over most of the current US Southwest (the border established by the treaty is very similar to today's border between the two nations) in exchange for $15 million dollars and forgiveness of some previous debt.