Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:19:5

And indeed, I fear the successors after me, and my wife has been barren, so give me from Yourself an heir  

And truly I fear my kinsfolk, namely, those who will succeed me ˹as closest after me˺ in kinship, such as ˹my˺ paternal cousins, after me, that is, after my death, ˹I fear˺ for the religion, lest they forsake it, as You have witnessed in the case of the Children of Israel, in the way that they changed ˹their˺ religion, and my wife is barren, she does not conceive. So grant me from Yourself a successor, a son,
القرآن:١٩:٥

وَإِنِّي خِفْتُ الْمَوَالِيَ مِنْ وَرَائِي وَكَانَتِ امْرَأَتِي عَاقِرًا فَهَبْ لِي مِنْ لَدُنْكَ وَلِيًّا  

{وإني خفت الموالي} أي الذين يلوني في النسب كبني العم {من ورائي} أي بعد موتي على الدين أن يُضيعوه كما شاهدته في بني إسرائيل من تبديل الدين {وكانت امرأتي عاقرا} لا تلد {فهب لي من لدنك} من عندك {وليا} ابنا.