Like many a loveless marriage of convenience, the union between President Trump and “his” generals has ended in recrimination and heartbreak.

After Trump impetuously announced a troop withdrawal from Syria last month, Defense Secretary Jim Mattis, a retired Marine four-star general, resigned on Dec. 20 — with a letter blasting the president for not “treating allies with respect” and not “being clear-eyed about both malign actors and strategic competitors.” Trump characteristically insulted him in return, demanding, “What’s he done for me?” and claiming that “President [Barack] Obama fired him and essentially so did I.” No, Mattis quit. Trump did fire White House Chief of Staff John F. Kelly, another former Marine general. During a post-firing interview , Kelly did not praise his boss’s achievements but rather his own success in averting disasters — including preventing Trump from breaking the law.

By then, two other generals were long gone. Michael Flynn, a retired Army three-star general, was forced out as national security adviser after just 24 days and is now a felon. His successor, H.R. McMaster, an active-duty Army three-star general, lasted just more than a year and left lamenting Trump’s failure to impose “sufficient costs” against Russia for its aggression.

Trump has been engaged in a war of words with two other retired general officers — Special Operations superstars William H. McRaven and Stanley A. McChrystal. Retired Navy Adm. McRaven, a SEAL who oversaw the raid that killed Osama bin Laden, said of Trump: “Through your actions, you have embarrassed us in the eyes of our children, humiliated us on the world stage and, worst of all, divided us as a nation.” Trump lamely shot back: “Wouldn’t it have been nice if we got Osama bin Laden a lot sooner,” as if it was McRaven’s fault the intelligence community had trouble tracking the leader of al-Qaeda.

McChrystal, a retired Army four-star general, described Trump as untruthful and immoral, leading Trump to retort with his characteristic crudity: “ ‘General’ McChrystal got fired like a dog by Obama. Last assignment a total bust. Known for big, dumb mouth. Hillary lover!” Note the quotation marks: Trump seems to be suggesting that anyone who criticizes him isn’t a real general.

Why was this marriage doomed from the start? Let us count the ways:

Generals believe in intensive study and preparation before acting. The best ones are students of history and politics. Mattis, who counseled his Marines to “engage your brain before you engage your weapon,” became famous for taking a library with him on every assignment. McRaven has written three books, including a well-regarded study of Special Operations forces. McChrystal produced a thoughtful memoir, as well as a book on leadership. Trump, by contrast, doesn’t read and disdains in-depth briefings in favor of making decisions based on his “gut” — and his viewing of Fox News.

Generals are supposed to live by an honor code. (Flynn obviously fell short.) All the service academies teach that you “will not lie, cheat, steal, nor tolerate” those who do. The consequences for violating that code are severe: Paul Whelan, who is now a prisoner in Russia, received a bad-conduct discharge from the Marines for attempting to steal more than $10,000 in Iraq. Trump lives by a very different code: Do anything you can get away with, whether it’s stiffing contractors, lying to the public or paying off mistresses.

Generals are nonpartisan. They serve presidents of both parties and must avoid any involvement in politics. Trump, by contrast, is pathologically partisan: He denounces Democrats as traitors who belong behind bars. One can only imagine what the generals thought as they watched Trump treat his visit to the troops in Iraq as though it was a campaign rally. Or when he deployed troops to the U.S.-Mexico border just before the midterm elections as a political stunt. The politicization of the military will be one of Trump’s baleful legacies.

Generals are dedicated to the United States’ allies. Trump’s generals spent years training and fighting alongside allied armed forces. They see allies as “force multipliers” that reduce the number of Americans sent into harm’s way. Trump sees allies as freeloaders who take advantage of our generosity. He seethed last year: “We’re like the piggy bank that everybody’s robbing.” Trump has no compunction about abandoning allies, whether they be Kurds in Syria or Afghans, by withdrawing U.S. troops. The generals, by contrast, see premature pullouts as a betrayal of sacred commitments to those who have risked their lives fighting alongside our forces.

With his insufferable boastfulness, Trump claimed, “I think I would have been a good general.” Actually, he would never have made it to first lieutenant, because his me-first ethos is so at odds with the military’s stress on service and sacrifice. All that Trump knows about the military seems to come from movies such as “Patton” and “Bloodsport.” His exposure to real-life generals revealed an unbridgeable chasm between the commander in chief and those under his command. The generals tried to shield the armed forces, and the world, from an out-of-control chief executive — and, in the process, they were themselves sullied to varying degrees. It was a well-intentioned enterprise but one doomed to defeat. Trump cannot stand being told what to do by those more competent and qualified than himself — or being disdained when he falls short of their exacting standards.