Image caption Pearl Mackie was recently cast as the Doctor's companion

The role of Doctor Who was previously offered to a black actor, executive producer Steven Moffat has revealed.

But he told the show's official magazine that "for various reasons, it didn't work out".

Moffat said the show had "no excuse" not to feature a more diverse cast, adding it would be "amazing" for it to have two non-white lead actors.

Pearl Mackie, whose father is from the West Indies, was recently cast as the Doctor's companion.

"We decided that the new companion was going to be non-white, and that was an absolute decision, because we need to do better on that. We just have to," Moffat said.

"I don't mean that we've done terribly - our guest casts are among the most diverse on television - but I feel as though I could have done better overall."

Moffat did not reveal name of the actor who had been approached to play the Doctor.

Prior to the casting of Peter Capaldi in 2013, there had been calls for a black actor to take on the role.

'No excuse'

Earlier this year, Undercover became the first BBC One drama to feature two non-white actors, with Adrian Lester and Sophie Okonedo in the leading roles.

Moffat, who is also Doctor Who's lead writer, said he would be keen for his show to do the same thing.

"Two non-white leads would be amazing. In fact, a lot of people would barely notice," he said.

"I certainly don't think there's ever been a problem with making the Doctor black, which is why it should happen one day.

Image copyright PA Image caption Steven Moffat will step down as executive producer at the end of next year's series

"Sometimes the nature of a particular show - historical dramas, for instance - makes diversity more of a challenge, but Doctor Who has absolutely nowhere to hide on this," he said.

"Young people watching have to know that they have a place in the future. That really matters. You have to care profoundly what children's shows in particular say about where you're going to be."

He added a more diverse cast would send out a positive message to the entertainment industry.

"Outside of the fiction, it's about anyone feeling that they can be involved in this industry as an actor, a director, a writer... It's hugely important, and it's not good when we fail on that. We must do better," he said.

Moffat is due to step down as executive producer at the end of next year's series and will be replaced by Chris Chibnall, the writer best known for ITV drama Broadchurch.

Moffat said the show must find new ways to get ethnic minority actors on screen in future.

"We've kind of got to tell a lie. We'll go back into history and there will be black people where, historically, there wouldn't have been, and we won't dwell on that.

"We'll say, 'To hell with it, this is the imaginary, better version of the world. By believing in it, we'll summon it forth'."

The BBC said it does not comment on its casting process.