President Donald Trump’s attacks on the four Democratic congresswomen, known collectively as “the squad,” appear to be a strange way to try to win reelection.

There is no doubt that Trump needs to motivate his base to win a second term, and his tweets and comments about immigrants and “socialism” are, at least in part, intended to energize his loyal supporters and demonize the entire Democratic Party. On one level, that certainly makes sense.

A less appealing opposition party is likely to attract fewer swing voters and have problems turning out its own weak partisans.

Since the president has not broadened his appeal and attracted new voters, he will in all likelihood need to rely next year on the same narrow Electoral College strategy that sent him to the White House in 2016.

That would entail losing the popular vote again but winning enough white voters without a college degree in key states like Pennsylvania, Michigan and Wisconsin to squeeze out another Electoral College victory.

Many of Trump’s core supporters undoubtedly agree with his characterization of “the squad” of four progressive freshmen, and making them the face of the Democratic Party has potential benefits for the president and Republicans.

But too much of Trump’s rhetoric does something else that actually undermines his prospects — it inflames Democrats of all stripes, reminding them why they feel they must defeat the president next year.

In other words, Trump is a turnout machine for the Democrats, as well.

The timing of Trump’s attacks on New York Rep. Alexandria Ocasio-Cortez and her compatriots is more than a little odd.

The president once again injected himself into a hot-button debate about tolerance, diversity, race and exactly who or what is an American just as the Democratic divide during the presidential nominating process was starting to raise questions about whether party progressives and pragmatists would both support the eventual nominee.

Instead of withdrawing from the limelight so that former Vice President Joe Biden, and Sens. Elizabeth Warren, Bernie Sanders and Kamala Harris could fight it out over “Medicare for All,” decriminalizing illegal immigration, free college, reparations and the Green New Deal, the president put himself in the middle of everything, essentially changing the subject in a way that benefits Democrats.

Obviously, Trump craves the limelight and the attention, and he believes he must continue to feed red meat to his supporters. But doing so inevitably angers, energizes and mobilizes those voters who find him offensive, or worse.

As we saw during the 2018 midterms, Trump is in serious trouble when Democratic turnout among key constituencies — people of color, younger voters and progressives — is strong, and when swing voters — suburbanites and whites with a college degree — slide away from the GOP and to the Democrats.

So, Trump faces a conundrum.

The more he interjects himself into controversial topics, the more cheers he hears from his base. He feeds on that enthusiasm, believing that his reelection prospects are enhanced when he takes on “the squad,” the national media, Hillary Clinton and socialism.

But Trump’s attacks invariably are sloppy. The more he ventures into hot-button topics, the more likely he is to offend voters, energizing core Democratic constituencies and alienating swing voters who sent him a message of disapproval in last year’s midterms.

Trump knows how to turn out his voters. Unfortunately for him, he invariably ends up turning out anti-Trump voters as well.

Given his low approval ratings, his showing in 2016 and the 2018 midterm results, that’s not a recipe for a Trump reelection in 2020.

Note: An earlier version of this column appeared initially in the July 17, 2019 issue of Roll Call.