Detroit’s bankruptcy and the problems facing its pension funds offer two important lessons to other communities. One is that state and local governments need to do a much better job managing retirement funds. The other is that they should not pre-emptively reduce hard-earned benefits at the first sign of trouble.

Several state and local pension systems around the country are under serious stress. Not surprisingly the hardest hit retirement funds are in places devastated by global economic forces like Detroit, as well as inland cities in California like Stockton, which was battered by the real estate collapse and has also sought bankruptcy protection. Other troubled funds include state-employee and teacher retirement systems in Illinois and Connecticut, where government officials have long mismanaged public finances.

The biggest problem is that officials have repeatedly failed to set aside enough money to cover the benefits they have promised workers, according to a recent report by Moody’s, the credit ratings firm. Some states and cities have compounded their problems by trying to compensate with risky bets, like investing heavily in hedge funds in hopes of earning high returns. (And hedge funds are hardly surefire winners.) Or, like Detroit, they borrowed money to sustain their pension systems without having a solid plan for repaying the new debt.

Avoiding a Detroit-like downward spiral requires discipline and intelligence. Most urgent, officials overseeing troubled funds need to save more money. They also should leave investment choices to seasoned professional managers. In some cases they might have no choice but to reduce benefits, which shouldn’t happen before other creditors are asked to take a haircut and before consulting with workers and retirees.