The 'Ta fang hsi-yu chi' by Hsuan-tsang (a Chinese scholar who wrote about India) tells the story of Apalala. Kasyapa Buddha was a man with the power to control the weather. He did so by controlling the evil dragons that possessed the power to bring storms. In return for his good will in controlling these storms, the local people offered him grain. Eventually, the people started to forget to offer the grain and Kasyapa grew angry. He prayed that he would become a dragon, so that he could punish them for their selfish behavior.
This prayer was eventually granted and after his death he became the dragon Apalala. He made his home in a pond in Udhyana (an old name for the area of the Swat valley). He destroyed the area with powerful storms and rain. This continued every crop season until Sakyamuni Buddha visited the area. He persuaded Apalala that what he was doing was wrong. They came to an agreement where Apalala would stop his destruction in return for one crop every twelve years. Rather than relying on the people to provide the offering, he would take it himself by flooding the land.