This is not the right answer, but if you're going to have open borders and free travel, something has to be done about benefit tourism, otherwise the states with the most generous welfare/benefit system will see the greatest migration and have to bear the greatest share of the costs, we've seen this with the Calais camp inhabitants and the "UK or bust" issues that occured there.
The only real solution is a single welfare system for the whole of the EU, which is impossible without fiscal and political union, which isn't going to happen any time soon.
So what is the answer?, because I can honestly state, that should Scotland, for instance, implement Universal Basic Income, our whole family would move there in a heartbeat, the Calais 'jungle' camps would be replaced with the Carlisle camps and the whole problem just shifts elsewhere.
So again, other than a single EU-wide welfare system, how do you stop welfare / benefit tourism?