You may have a food allergy or you may simply get bad indigestion. Or maybe you over-eat. The food allergy would be something like the wheat of the pasta, or the tomatoes in the sauce - not just "allergic to spaghetti."
If you think it's a food allergy then your doctor can run a quick allergy test to see. But also, try a different spaghetti recipe with something less acidic, like a white sauce.