Scientists think they've figured out why chocolates and wine can trigger migraines in some unlucky people: it's down to gut microbes and the way they interact with chemicals in food.

This unfortunate bacteria-powered chain of events turns chemicals called nitrates - found in chocolate, wine, processed meat, and other foods - into nitric oxide byproducts. And it's these byproducts, which have been linked to migraines in previous research, that can cause a splitting headache.

To find the link between the two, researchers from the University of California, San Diego (UCSD) analysed 172 oral samples and 1,996 stool samples from their American Gut Project database.

The results showed that people who experienced migraines also had higher levels of the gut microbes that can modify nitrates.

"There is this idea out there that certain foods trigger migraines - chocolate, wine, and especially foods containing nitrates," says one of the researchers, Antonio Gonzalez. "We thought that perhaps there are connections between what people are eating, their microbiomes, and their experiences with migraines."

When nitrates enter the body via food and drink, bacteria access them and use them as fuel. But it doesn't end there, because the bacteria's own waste products, called nitrites, eventually become nitric oxide in our blood.

Nitric oxide isn't all bad, because it dilates our blood vessels and can aid cardiovascular health by boosting blood circulation. But it's thought that sometimes this dilation and inflammation can increase a person's risk of migraines.

In fact, patients experiencing chest pains or heart problems often take drugs containing nitrates - but the problem is that more than 80 percent of them report headaches as an unwanted side effect. The question is whether their bacterial microbiomes are to blame.

After sequencing the bacteria from the samples in the study, the UCSD team used a bioinformatics software program called PICRUSt - pronounced "pie crust" - to identify which genes were likely to be present in the microbes of each individual.

Genes that encoded nitrate, nitrite, and nitric oxide-related enzymes were all shown to be more abundant in the mouths and guts of migraineurs - the term for people who regularly experience migraines.

While that lends weight to the argument that the bacteria living in our guts and mouths might be the link between nitrates in food and migraines, the researchers admit more work is needed to prove this hypothesis.

"It remains to be seen whether these bacteria are a cause or result of migraines, or are indirectly linked in some other way," said American Gut Project manager Embriette Hyde, who also worked on the study.

To team intends to run follow-up studies looking at people with particular types of migraines to further investigate the association. If it really does exist, one day there could be a range of treatments to alleviate migraines, like a "magical probiotic mouthwash", Gonzalez suggests.

Until then, the best advice scientists have is that you might want to take a pass on the red wine and chocolate. Sheesh… sorry, guys.

"If you suspect that nitrates are causing you migraines," Gonzalez says, "you should try to avoid them in your diet." 

The findings are published in mSystems.