Alfonso was a prolific author of Galician poetry, such as the "Cantigas de Santa Maria", which are equally notable for their musical notation as for their literary merit. Alfonso's scientific interests—he is sometimes nicknamed the Astrologer ("el Astrólogo")—led him to sponsor the creation of the Alfonsine tables, and the Alphonsus crater on the moon is named after him. He also sponsored the work of historians, who for the first time placed Spain—he would have called it that—in the context of world history. As a lawmaker he introduced the first vernacular law code in Spain, the "Siete Partidas". He created the Mesta, an association of sheep farmers in the central plain, but debased the coinage to finance his claim to the German crown. He fought a successful war with Portugal, but a less successful one with Granada. The end of his reign was marred by a civil war with his eldest surviving son, the future Sancho IV, which continued after his death.