Mexico became an independent country in 1821, after the Mexican War of Independence (1810–1821) against Spain.
1849 was during the Mexican–American War aftermath (Treaty of Guadalupe Hidalgo, 1848), when Mexico ceded ~55% of its territory to the U.S. It was already a sovereign nation for 28 years.