WASHINGTON – Former President Barack Obama warned Democrats about the dangers of rigid ideological dogmatism, which he said can lead to a "circular firing squad" at an Obama Foundation event in Berlin on Saturday.

Obama made the comment while discussing the importance of compromise in a functioning democracy at the town hall-style forum with "emerging European leaders."

"One of the things I do worry about sometimes among progressives in the United States, maybe it's true here as well, is a certain kind of rigidity where we say, 'Ah, I'm sorry, this is how it's gonna be.' And then we start sometimes creating what's called a circular firing squad where you start shooting at your allies because one of them is straying from purity on the issues. And when that happens, typically the overall effort and movement weakens," Obama said.

The former Democratic president's warning comes as his party appears increasingly divided between left-wing politicians such as New York Rep. Alexandria Ocasio-Cortez and Vermont Sen. Bernie Sanders who espouse democratic socialism, and more moderate Democrats advocating more incremental reforms.

Exclusive:How Nancy Pelosi is leading divided Democrats through political turmoil, Trump's administration

More:New York Democrat Max Rose derides 'socialist' Green New Deal, welcomes AOC challenge

That tension is also emerging in the race for the 2020 Democratic presidential nomination where voters will weigh whether to support figures calling for sweeping progressive policies such as Medicare for All and the Green New Deal, or more establishment Democratic figures, such as Obama's former running mate Joe Biden who, if he decides to run, might have more appeal in the general election.

Who is running for president?:An interactive guide

Obama said that if they want to get things done, voters and politicians need to accept that they aren't going to get "100% of what you want because somebody else is going to have a slightly different set of interests or slightly different set of values."

"You have to recognize that the way we've structured democracy requires you to take into account people who don't agree with you," he said.

But he also warned the audience that they should also remain to true their "core principles."

"You can't set up a system in which you don't compromise on anything, but you also can't operate in a system where you compromise on everything."

Obama blamed some of the inability to find common ground on the media, which he said are geared to "inflame" and "provoke."

He said he advises his wife Michelle Obama, "Don't watch cable news shows. They're designed to get you mad. That's what their purpose is. Social media is worse. They're designed to make you click."

"You've got social media that was once considered to be the network that would provide us greater understanding, now suddenly appears to be a tool that is used to spread disinformation and hatred and suspicion," said Obama, who was one of the first politicians to effectively use social media.

"We are collectively, all of us, going to have to find ways in which we improve the conversation on the internet and in social media. It is going to be difficult to do."

More:Barack Obama traveled extensively as president, but trips with his daughters were most cherished