Remember, you are not writing the D major scale.
You correctly recognise that it contains only naturals and sharps, no flats.
When looking at the full collection of intervals relative tk D, you are not seeing D as the root note of a major scale.
Go by the letters and their ordinal value as a scale degree in that major scale as a useful tool.
D major scale:
D, E, F#, G, A, B, C#
Any note using letter D must be a ‘1’ of some kind.
Any note using letter E must be a ‘2’ of some kind.
Any note using letter F must be a ‘3’ of some kind.
Any note using letter G must be a ‘4’ of some kind.
Any note using letter A must be a ‘5’ of some kind.
Any note using letter B must be a ‘6’ of some kind.
Any note using letter C must be a ‘7’ of some kind.
The scale degrees as intervals are:
1, M2, M3, P4, P5, M6, M7
That is seven of the twelve leaving five intervals to fill.
Between 1 and M2 is m2 [ Eb in relation to D ].
Between M2 and M3 is m3 [ F in relation to D ].
Between P4 and P5 is A4 and D5[ G# and Ab in relation to D ].
Between P5 and M6 is m6 [ Bb in relation to D ].
Between M6 and M7 is m7 [ C in relation to D ].
See if this topic enhances your understanding.