The Mexican-American War was fought between the United States and Mexico from 1846 to 1848. It was primarily over the territory of Texas. Texas had been a state of the country of Mexico since 1821 when Mexico gained its independence from Spain. The Texans, however, began to disagree with the government of Mexico.