President Trump spoke about banning transgender people from the military in Bedminster N.J. on Aug. 10. (The Washington Post)

This post has been updated, 9:19 a.m.

Deep in the heart of Texas, Gov. Greg Abbott and Lt. Gov. Dan Patrick must have thought they had a political winner.

Patrick, a conservative crusader and talk-radio host, got Abbott to call a special session this summer of the Texas legislature — an emergency! — largely for the purpose of passing a “bathroom bill” to restrict the use of public restrooms by transgender people.

It was opportunistic and cynical, a solution in search of a problem. Proponents of the “Privacy Act” raised bogus fears about men exposing themselves to, and assaulting, women and girls in showers and toilets. Texans, Patrick proclaimed, “don’t want their children showering together, boys and girls in the 10th grade . . . and women want to be protected.”

But things didn’t go according to plan. The business community objected, fearing the sort of economic boycott that hit North Carolina over a similar bill. Police chiefs called the legislation counterproductive. Polling showed that Texans, particularly young Texans, didn’t think the issue a priority. Support for the bill shrank from an earlier attempt at passage. The House speaker, a Republican, refused to bring it up. The legislature adjourned last week with the bathroom bill swirling in the drain.

President Trump's tweeted transgender military ban on July 26 drew immediate criticism from both Democrats and Republicans, who were caught unaware by the decision. (Jenny Starrs/The Washington Post)

Even deeply conservative Texas, it seems, has no appetite for discrimination against transgender Americans. Yet here comes President Trump with a fresh attempt at just such discrimination.

Trump on Friday directed the Pentagon to stop allowing transgender people to enlist in the military. His order also gave military leaders power to remove transgender people already serving – a policy he signaled last month on Twitter.

Never mind that transgender people have been serving openly in the military, essentially without incident. Never mind that the generals weren’t asking for such a ban. And never mind the American tradition that any able-bodied patriot should be allowed to serve.

The proposed ban on transgender enlistments follows the administration’s revocation earlier this year that gave transgender students protections in public schools. In both cases, Trump stands athwart history, yelling, “Go back.”

Just as a consensus has rapidly formed in recent years in support of same-sex marriage, the experience in Texas makes clear that acceptance of transgender people is moving inexorably in the same direction. Trump’s policy is a rear-guard action, trying to codify discrimination even as Americans become more tolerant.

A Quinnipiac University poll this month finds that 68 percent of voters believe transgender people should be allowed to serve in the military. A majority of military households agree. By 46 percent to 14 percent, voters said more acceptance of transgender people would be “a good thing for the country” rather than bad. Even a third of Republicans accept transgender service.

Trump is, as usual, playing to his (dwindling) base. In doing so, he is aligning himself, literally, with the past over the future. Younger voters are the most accepting of transgender people and older voters the least. Quinnipiac found that 54 percent of those aged 18 to 34  believe more transgender acceptance would be good for the country, compared with only 35 percent of those 65 and older.

President Trump tweeted that transgender people would be barred from the military, citing their "tremendous medical costs," but the Pentagon spends less on transgender medical bills than it does on erectile dysfunction medication. (Erin Patrick O'Connor,Osman Malik,Christopher Ingraham/The Washington Post)

So it goes for Trump generally. He has the strong support of just 26 percent of the country — and that falls to 20 percent among the youngest voters while jumping to 33 percent among the oldest. Now he’s talking about shutting down the government unless Congress funds his border wall, an idea that Americans oppose by nearly 2 to 1. Support for the wall draws greatest opposition from young voters and least opposition among older voters.

What this means is Trump is, in an actuarial sense, charting a course to oblivion. History is moving in one direction and Trump in the other.

That’s where Patrick, Abbott and the Texas bathroom-bill proponents were heading. Polling by the University of Texas and the Texas Tribune found that Texans did not share their leaders’ sense of alarm about transgender rights. Only 26 percent of voters considered it a “very important” matter (44 percent considered it important) for the legislature, and older voters were 10 percentage points more likely than younger voters to think it important. Support within the House actually declined over time: There were 80 co-sponsors during the regular session but only 60 in the special session, the Tribune noted.

For good reason. The bill had little substance: no penalties for those who violated the law, no increased punishments for crimes in restrooms, no real enforcement mechanism. It was just rank discrimination.

Texas rejected that. Inevitably, the nation will too.

Twitter: @Milbank

Read more from Dana Milbank’s archive, follow him on Twitter or subscribe to his updates on Facebook.