Every time African migrants are attacked in South Africa, outrage ripples across the continent.

Governments issue condemnations, civil society mobilises, diplomatic tempers flare and then, within a news cycle or two, the story fades.

That condemnation is justified. No African should be assaulted, displaced or killed for having crossed a border in search of safety or opportunity.

The recurring violence against migrants in South Africa is a real and continuing moral and political failure.

But if the rest of the continent keeps treating xenophobia as something that happens in South Africa rather than something that runs through Africa, we are letting ourselves off far too easily.

The uncomfortable truth is that xenophobia in Africa is older than South African democracy itself. Long before the attacks in Johannesburg and Durban in 2008, several African governments had already built policies around expelling fellow Africans.

Ghana's 1969 Aliens Compliance Order forced roughly 140 000 to 200 000 undocumented migrants out of the country within weeks, a great many of them Nigerians who had lived and traded there for years.

Nigeria answered in kind in 1983, expelling well over a million undocumented migrants, many of them Ghanaians, in the episode that gave the world the phrase ‘Ghana Must Go’.

Comparing the Nigerian and South African experiences directly, I argue that both cases grew out of the same underlying pattern: economic strain turning migrants into the most convenient available target.

In Côte d'Ivoire, meanwhile, the politics of ivoirité turned long-settled migrants and their children into permanent outsiders, feeding a nationality dispute that helped drag the country into civil war.

South Africa did not invent any of this. It inherited a continental habit and simply expressed it more violently than most.

That habit shows no sign of dying out. In Ghana, sections of the business community have recently called for Nigerian traders to leave, accusing them of crowding out local shopkeepers.

It hasn't turned into the kind of organised violence South Africa has seen, not yet but the underlying story is identical: foreigners get blamed for unemployment, for hardship, for a shrinking slice of the pie.

Xenophobia rarely starts with a mob. It starts with a politician or a trade association deciding that migrants make a more convenient villain than bad policy does.

So is South Africa becoming Africa's scapegoat? I don't think the answer is a simple yes or no. South Africa absolutely has to answer for the killings, the looting and the displacement that keep happening within its borders.

But letting the conversation stop in South Africa lets every other government off the hook for its own history and its own present-day rhetoric.

Selective outrage is cheap and it costs Africa something real: it undermines the continent's claim to any kind of shared moral authority. You cannot credibly condemn a xenophobic riot in Johannesburg while quietly tolerating anti-migrant rhetoric in your own capital.

There's a bigger story underneath all of this and it's the slow unravelling of Pan-Africanism. The generation that built the Organisation of African Unity — Nkrumah, Nyerere, Azikiwe, Lumumba, Mandela and others — didn't just fight colonial rule.

They fought against the idea that colonial borders should carve Africans into permanently separate, mutually suspicious peoples. That vision is what the OAU and later, the African Union, was meant to carry forward. Increasingly, though, a narrower, more defensive nationalism is crowding that vision out.

Economic hardship has sped this along. When unemployment rises, inflation bites and public services buckle, blaming the foreigner next door is far easier than fixing the institutions that actually failed.

But the evidence keeps pointing the same way: unemployment, inequality and poverty in Africa are, overwhelmingly, the products of structural economic and governance failures, not the presence of migrants.

Xenophobia doesn't solve any of that. It just gives politicians somewhere else to point to.

That makes the current moment particularly hard to justify.

Africa is simultaneously celebrating the African Continental Free Trade Area (AfCFTA) and pushing the African Union's Protocol on the Free Movement of Persons while allowing anti-migrant sentiment to fester in country after country.

The Ecowas Free Movement Protocol, which predates the ‘Schengen’ arrangement, is seen as West Africa's own attempt that depends entirely on member states' willingness to actually honour it rather than quietly work around it.

Arguing further, the continental version — the African Union Protocol on Free Movement — cannot meaningfully reduce Africa's chronic border porosity unless states treat it as binding policy rather than a diplomatic gesture. That is not a small contradiction; it is a fatal one.

A continental market cannot function if the people who are supposed to trade across it, staff it and build it are unwelcome the moment they cross a border. Free movement of goods, services and capital means very little if the people carrying them are treated as suspects.

The African Union needs to stop treating xenophobia as a crisis to be managed with statements after the fact. It should be treated as a governance failure in its own right.

That means putting real weight behind the free movement protocols instead of leaving them half implemented, building an early warning system that can flag anti-migrant rhetoric before it turns violent, helping member states design humane migration policies and funding public education that reminds people what Pan-Africanism was actually meant to achieve.

The AU is one of the few institutions positioned to make migration governance and human dignity work together rather than against each other but only if it decides to use that position.

None of this means African states have to fling their borders open without any control. Every sovereign country has the right to manage immigration and enforce its laws. But there is a hard line between regulating a border and using that border as an excuse for discrimination, collective punishment or violence against people because of where they were born.

Migration governance built on lawful institutions, transparent rules and real regional cooperation is a legitimate exercise of sovereignty. Mob violence and political scapegoating are not, whatever language is used to dress them up.

In the end, South Africa's experience should be read as a warning to the whole continent, not an excuse to isolate one country and move on.

Xenophobia is an African problem and it needs an African answer. South Africa has to confront the violence happening inside its own borders but Nigeria, Ghana, Côte d'Ivoire and every other African state carrying its own history of expelling or scapegoating migrants owe the continent the same reckoning.

If Pan-Africanism is going to mean more than a line in a history book, Africa has to trade selective outrage for collective responsibility. Otherwise the real question isn't whether another country will go through its own wave of xenophobic violence. It's simply which one goes next.

Dr Samuel Kehinde Okunade is a senior lecturer in the department of border and migration studies at Lagos State University, Nigeria.