turning to God only in one's trouble; praying only when in need
Proverbial expression criticizing those who seek divine help only when facing difficulties, ignoring faith in good times. Often used to describe opportunistic or last-resort reliance on religion.
Going to a shrine only before exams, when you're not usually devout, is a perfect example of turning to God only in your trouble.
He only prays when he's in trouble—a classic case of turning to God only in one's trouble.
Synonymous expression with the same meaning; 叶わぬ時 emphasizes unfulfilled wishes, while 苦しい時 emphasizes hardship.
A fixed idiomatic expression combining 叶わぬ (negative form of 叶う, 'to come true') + 時 ('time') + 神頼み ('prayer to gods'). The exact origin is uncertain, but it reflects a common proverbial criticism of opportunistic faith.