When the Qing dynasty tried to enforce the ban on opium imports in 1839, the British government went to war, ostensibly to protect the lives and rights of British traders, but really to protect the drug trade. The war lasted three years, until 1842.