Sayyiduna Abu Hurayrah (may Allah be pleased with him) says that the Messenger of Allah (peace and blessings be upon him) said: "Whoever swears an oath to do something and then considers another thing better than it, let him do the good thing and give the expiation for his oath."
Imam al-Shafi'i (may Allah have mercy on him) says: Obedience to Allah lies in this: when the other thing is better, do it and pay the expiation for the oath. From this it is known that every vow, and every covenant of a Muslim or of a polytheist, is to be fulfilled if it is permissible; a covenant involving disobedience to Allah is not to be fulfilled.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجزية / 18854