Consider a branching random walk on the real line with a random environment in time (BRWRE). A necessary and sufficient condition for the non-triviality of the limit of the derivative martingale is formulated. To this end, we investigate the random walk in a time-inhomogeneous random environment (RWRE), which is related to the BRWRE by the many-to-one formula. The key step is to figure out Tanaka’s decomposition for the RWRE conditioned to stay non-negative (or above a line), which is interesting in itself.