By the end of the Song dynasty, the center of trading had moved downstream of the Wusong River to Shanghai. It was upgraded in status from a village to a market town in 1074, and in 1172, a second sea wall was built to stabilize the ocean coastline, supplementing an earlier dike. From the Yuan dynasty in 1292 until Shanghai officially became a municipality in 1927, central Shanghai was administered as a county under Songjiang Prefecture, which had its seat in the present-day Songjiang District. Two important events helped promote Shanghai's developments in the Ming dynasty. A city wall was built for the first time in 1554 to protect the town from raids by Japanese pirates. It measured high and in circumference. A City God Temple was built in 1602 during the Wanli reign. This honor was usually reserved for prefectural capitals and not normally given to a mere county seat such as Shanghai. Scholars have theorized that this likely reflected the town's economic importance, as opposed to its low political status. During the Qing dynasty, Shanghai became one of the most important sea ports in the Yangtze Delta region as a result of two important central government policy changes: in 1684, the Kangxi Emperor reversed the Ming dynasty prohibition on oceangoing vessels—a ban that had been in force since 1525; and in 1732, the Qianlong Emperor moved the customs office for Jiangsu province (; see Customs House, Shanghai) from the prefectural capital of Songjiang to Shanghai, and gave Shanghai exclusive control over customs collections for Jiangsu's foreign trade. As a result of these two critical decisions, Shanghai became the major trade port for all of the lower Yangtze region by 1735, despite still being at the lowest administrative level in the political hierarchy. In the 19th century, international attention to Shanghai grew due to European recognition of its economic and trade potential at the Yangtze. During the First Opium War (1839–1842), British forces occupied the city. The war ended in 1842 with the Treaty of Nanking, which opened Shanghai as one of the five treaty ports for international trade. The Treaty of the Bogue, the Treaty of Wanghia, and the Treaty of Whampoa (signed in 1843, 1844, and 1844, respectively) forced Chinese concession to European and American desires for visitation and trade on Chinese soil. Britain, France, and the United States all carved out outside the walled city of Shanghai, which was still ruled by the Chinese.