D mesons in a magnetic field