I do not know whether it fits your question, but consider the USSR. While there was no such law that explicitely prohibited migration, most people could not sell or buy or rent the realty by their choice because all flats in multy-storey buildings were state-owned.
In theory one could make an agreement on flat exchange, but to do so you had to find somebody who wanted to move to the location where you lived before. Thus the net migration to a city would be zero because if one moves in, the other moves out of it.
One could also buy a house, but private houses were mostly located in rural areas, outside of big cities.
There were other options of course, for instance one could buy a flat built by a cooperative, but for all kinds of property there was the same strict regulation on whom you can allow to live with you (only close relatives) and how many people can live in a given space.
Finally one could of course rent an apartment in a hotel, but this again would be very expensive for an average citizen to live for a long time.
Of course, the population of big cities was often growing very fast in the USSR, but this happened mostly following the official rules so that people populated state built and owned flats, according the established standard norm of population density, which specified the number of sq meters of living room per person.
Those living in a place unofficially could be fined badly and otherwise punished.