Adding to the current answers, there can be many reasons for food cravings and avoidance.
Orloff & Hormes (2014) points out that the main hypotheses discussed in research receive little support, with the notable exception of a postulated role of cultural and psychosocial factors.
They also point out interesting links with eating disorders. For example, they point to research on food cravings that have been identified not only as reliable predictors of subsequent consumption of the desired food, but also as potential triggers for episodes of binge eating, especially in bulimic and overweight individuals.
Cravings during pregnancy seem to be different. While Miller (2011) points out that
It’s a common misbelief that food cravings are a signal from the body that it’s missing some nutrient
Caitlyn Placek (2017) states that
The onset of cravings for items not typically desired is often considered a hallmark of pregnancy. Given the ubiquity of cravings, this phenomenon remains surprisingly understudied.
Fetal nutritional needs maybe are small early in pregnancy compared to later (Tierson, et al. 1985), but nevertheless, there are specific fetal nutritional needs which are hopefully fulfilled. Anecdotally, my wife craved for lots of liver, and after birth it was found the baby had next to no thyroid gland. Severe iodine deficiency causes hypothyroidism that results in impaired somatic growth and motor development in children (Chung, 2014) and according to WebMD
There are few foods that are as nutritionally dense as beef liver. A three-ounce serving of liver can provide 14 mcg of iodine along with the many other vitamins and nutrients it contains.
Quoting from Orloff & Hormes (previously mentioned);
Women experience an increase in food cravings at two specific times during their life — when perimenstrual and when prenatal Orloff & Hormes, 2014]1).
The prevalence of excess gestational weight gain (GWG) is a growing concern due to its association with adverse health outcomes in both mothers and children. To the extent that prenatal food cravings may be a determinant of energy intake in pregnancy, a better understanding of craving etiology could be crucial in addressing the issue of excessive GWG. This paper reviews the available literature to corroborate and/or dispute some of the most commonly accepted hypotheses regarding the causes of food cravings during pregnancy, including a role of (1) hormonal changes, (2) nutritional deficits, (3) pharmacologically active ingredients in the desired foods, and (4) cultural and psychosocial factors.
[...]
Various psychosocial factors appear to correlate with excess GWG, including the presence of restrained eating. Findings strongly suggest that more research be conducted in this area.
They also pointed out with references that the most common trajectory of food cravings across gestation shows a peak in frequency and intensity during the second trimester, followed by a subsequent decline as the pregnancy progresses to term.
Research has also consistently documented a significant drop in cravings following delivery (Worthington-Roberts et al., 1989; Belzer et al., 2010).
References
Belzer, L. M., Smulian, J. C., Lu, S. E., and Tepper, B. J. (2010). Food cravings and intake of sweet foods in healthy pregnancy and mild gestational diabetes mellitus. A prospective study. Appetite 55, 609–615. https://doi.org/10.1016/j.appet.2010.09.014
Chung, H. R. (2014). Iodine and thyroid function. Annals of Pediatric Endocrinology and Metabolism 19(1), 8-12. https://doi.org/10.6065/apem.2014.19.1.8
Miller, R. S. (2011). Nutritional needs during pregnancy. Nursing made Incredibly Easy, 9(5), 21-24. https://doi.org/10.1097/01.NME.0000403193.68168.d0
Orloff, N. C., & Hormes, J. M. (2014). Pickles and ice cream! Food cravings in pregnancy: hypotheses, preliminary evidence, and directions for future research. Frontiers in psychology, 5, 1076. https://doi.org/10.3389/fpsyg.2014.01076
Placek, C. (2017). A test of four evolutionary hypotheses of pregnancy food cravings: Evidence for the social bargaining model. Royal Society open science, 4(10), 170243. https://doi.org/10.1098/rsos.170243
Tierson, F. D., Olsen, C. L., & Hook, E. B. (1985). Influence of cravings and aversions on diet in pregnancy. Ecology of Food and Nutrition, 17(2), 117-129. https://doi.org/10.1080/03670244.1985.9990886
Worthington-Roberts, B., Little, R. E., Lambert, M. D., and Wu, R. (1989). Dietary cravings and aversions in the postpartum period. Journal of the American Dietetic Association, 89(5), 647-651. https://doi.org/10.1016/S0002-8223(21)02220-3