Hello @Community member and welcome to the Community :)
Yes, it is possible to migrate from MCU1 to compatible MCU2 using STM32CubeMX.
The following articles will help you on how to use STM32CubeMX to find and switch from one STM32 to another using STM32CubeMX :
How to find compatible devices for an MCU? STM32G473CB as example
How to export a project configuration to a compatible STM32
How to switch from one STM32 to another using STM32CubeMX
MCU1 to MCU2 migration option within STM32CubeIDE
Hope my answer helped you!
When your question is answered, please close this topic by choosing Select as Best.
Imen
In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks