The medium mass modification may lead to a squeezing effect. In the baryonic medium, the mass of D meson was expected to reduce and the in-medium masses of D+ and D− may show a splitting effect, and the chemical potential of D meson may be not zero. We study the squeezing effect on the yield ratio D+∕D− with nonzero chemical potential. Due to the in-medium mass splitting, the squeezing effect on the momentum distributions of D+ and D− are different. Without the squeezing effect, the yield ratio D+∕D− remains constant as the transverse momentum increases. The yield ratio D+∕D− is affected by the squeezing effect, resulting in a dependence on transverse momentum. An increase in transverse momentum leads to a decrease in the yield ratio, especially when there is a high chemical potential. Additionally, the in-medium mass splitting amplifies this phenomenon. The yield ratio D+∕D− with nonzero chemical potential approaches 1 when there is a large average in-medium mass reduction, which becomes more evident at higher transverse momentum. The study of the squeezing effect on the yield ratio D+∕D− with nonzero chemical potential may be meaningful for the CBM and PANDA experiments of the FAIR project at GSI.