President Donald Trump has come under fire this week after reportedly asking lawmakers on Thursday why the United States would accept more people from “shithole countries” — which he defined as Haiti, El Salvador and parts of Africa — during a meeting in the Oval Office about a potential immigration deal.

While the President’s vulgar phrasing may be unprecedented, his question comes with a long history. At various times in the past, America’s immigration system has openly favored some countries over others, with the system set up to specifically keep out immigrants from “countries that are doing badly,” as Trump put it in a follow-up tweet, often for reasons that were based on prejudice.

Mae Ngai, an immigration historian at Columbia University, spoke to TIME about the historical context behind Trump’s comment.

TIME: The President’s reported comments suggested that he would want the immigration system to favor potential immigrants from some countries and make things harder for those from other places. Has the U.S. ever done something like that, singling out specific “shithole countries”?

NGAI: In the 19th century, we had virtually open borders. Laborers from Europe, they all just came. The only exception was the Chinese, who came for the same reason that European laborers did in the late 19th century — but because of racism, Congress passed the Chinese Exclusion law in 1882. The Chinese were the first and only group to be singled out by name for exclusion. We’ve now singled out countries under the “Muslim ban,” but until that time, the Chinese held that dubious distinction. [The Exclusion Act] was repealed in 1943 during World War II, because China was a war ally of the U.S., but it was a foreign policy measure. They set a quota of 105 [people] per year, so that shows that they didn’t want more Chinese immigrants.

Why was China targeted?

It was a racialization of economic competition. They came over for the Gold Rush. They came over to work. Everyone in California, practically, was a migrant, except for the indigenous people and people of Spanish descent who had been there for hundreds of years. The political nativism against the Chinese was based on a racist theory that the Chinese were slaves. [Nativists] thought having slaves would depress the rights and wages of free workers. They were using it [“slave”] as a racial epithet. The Chinese suffered not only exclusion but violence, discrimination, harassment throughout the period of exclusion. But these Chinese weren’t slaves; they were voluntary immigrants like everyone else.

How did things change during the great wave of immigration at the turn of the 20th century?

There was high immigration from Europe, especially from Southern Europe, like Italy or Greece, and also Eastern Europe; Poland, Russia, Hungary. There was a nativist movement against these immigrants, who were almost entirely low-skilled workers who came and fueled the industrial revolution. The industrialization of the U.S. was done by these workers. About 25 million people came during this period, and there was a lot of debate similar to what you hear today, things said about Italians similar to what Trump says about Mexicans — “they’re criminals”; “they steal American jobs.”

In 1924, Congress passed the National Origins Act quotas, which restricted immigration to 15% of what it had been before World War I. So only 150,000 were let in a year, whereas it had been a million a year just coming naturally before the war. So for the first time, you had numerical limits, and they distributed that number according to racial favorites. Great Britain had a huge quota, as did Germany, but Italy and Hungary, had tiny, tiny quotas, and that was an attempt to stop that immigration. There’s always been this history of favoring some over others.

Get our History Newsletter. Put today's news in context and see highlights from the archives. Please enter a valid email address. Sign Up Now Check the box if you do not wish to receive promotional offers via email from TIME. You can unsubscribe at any time. By signing up you are agreeing to our Terms of Use and Privacy Policy . This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply. Thank you! For your security, we've sent a confirmation email to the address you entered. Click the link to confirm your subscription and begin receiving our newsletters. If you don't get the confirmation within 10 minutes, please check your spam folder.

And the 1965 Immigration Act was another milestone.

There was no numerical quota on a western-hemisphere country until 1965. In 1965, when national origin quotas had been repealed, Congress replaced it with a system of so-called equal quotas. Every country gets the same number, so it was supposed to get rid of racial favoritism. But should Mexico have the same limit as Belgium? So even though we have high levels of migration from non-European countries, in another sense it’s very unfair. The long waits for a green card that people talk about are only for about four countries — Mexico, India, China, the Philippines. Within those quotas, you have preferences. So the family preferences are adult married children or adult siblings of American citizens, that’s what Trump thinks is “chain migration.” People bring family members over. That’s how his mother came over, because she had a sister here.

We have a system now that on the surface is fair, but in reality it’s unfair. That law, the 1965 Immigration Act, was a Civil Rights-Era act, and it was very much in a civil rights mindset. In the U.S., civil rights means you treat every individual equally. This was morphed into “treat every country equally,” but not all countries are equal, so in practice it became a way to limit immigration from certain countries.

The countries that are now at the center of the discussion haven’t really come up yet. What’s behind recent migration from African nations to the U.S.?

African migration was low even after ’65 because the big African migration was slavery. But in terms of modern African migration, that only increased after 1990 with the so-called “diversity lottery.” In 1990, Congress added 50,000 a year as a diversity category, and that was actually meant to bring in more white people. It was meant for countries that had low immigration. They wanted more Europeans where there had not been that many, because Europe was prospering. People don’t migrate when their countries are doing really well. One of the unintended consequences of the diversity lottery is that Africans used it. You didn’t have to have a relation in the U.S., so people come from Nigeria or Ghana; there’s actually a middle class of very skilled professionals and technical people in those countries.

Have U.S. attitudes towards countries changed if their residents experienced a natural disaster or are caught in a political conflict?

We have a refugee law that was passed in 1980, when there was a lot of pressure on the U.S. to accept more refugees internationally. Before 1980, we had no official refugee policy. [The U.S.] had a Cold War policy, so in the ’50s, they brought in thousands of people from Hungary during the Hungarian uprising, then it was Cuba, then it was the Indochinese countries after the war. But Haitians who were fleeing the Duvalier regime were interdicted at sea and sent back because [the U.S.] said they weren’t refugees, though they obviously were, but it was a U.S-backed military regime — and it was racist. So we had an ad hoc system which favored only people from Communist countries.

Then in 1980, after pressure from human-rights movements around the world, we adopted a refugee policy that uses the international standard of what defines a political asylee and a refugee. A refugee could be from a natural disaster or war, or asylum refers to people who have a reasonable fear of persecution if they return to their home country based on their political beliefs or religion. That’s 50,000 a year, and the president can raise it or lower it, so that’s why we have, in recent years, people who have come from Sudan and Somalia and Burma.

Migration is a global phenomenon. It’s as old as human industry, so when states try to stop it or control it or regulate it, it invariably creates a whole host of other problems.

Write to Olivia B. Waxman at olivia.waxman@time.com.