Parliamentary system
This issue does not happen in Parliamentary system, where the prime-minister is elected indirectly, by the parliament itself. As a consequence a divided government is impossible. Even if the political views change with time and the prime-minister lose its support from parliament, it can be replaced with a motion of no confidence. Effectively, both measures make it impossible to create a divided government.