Ok I know a lot of cities weren't surrounded by vast, fertile plains, but for those that were, why didn't they fortify their food source, they could survive a siege for much longer if not indefinetly. I would assume buiding walls was very expensive but were there any cities that could afford it but didn't do it and why?
The villages in reality differed quite a bit, but for the sake of this post I'll allow myself to use rough approximations and averages. As the question assumes the existence of well-developed fortifications and siege warfare in Europe, let's use the timeframe of High Middle Ages before the Black Plague, i.e late 13th to mid 14th century. For the following calculations I will be using the data for the villages in Germany, Bohemia and Poland that correspond quite well with the data for France or England in the same period, especially at this level of approximation.
We can safely assume that the average village consisted of roughly 40 hearths (households) (in 14th century Germany a village with 20 households was considered 'small' and one with 60 households was, conversely, big) thus housing close to 250-300 people, including children.
Now, an average English household usually held the land equal to one yardlength, equal to roughly 30 acres defined as 40 by 4 perches (5,5 yard or 5 meters). This means that every household had roughly 145.200 square yards or 12 hectares of land. This corresponds to the situation in Germany or Poland, where single household rented a land area equal to 10-16 hectares while 25 hectares was considered a substantial amount, capable of easily feeding the family and leaving something for trade (given favourable weather of course). Now, assuming that the all households are roughly equal economically (which is a simplification as mayors could have been holding 100 acres of more), this gives us the area of at least 480 hectares for a single village, with the part of land used for meadows under three-field system already factored in. A small town was usually supported by between four and ten villages, let's average it to six, what gives us 2880 hectares, so we can safely make that 3000 after counting the area of city in. And this is a a significantly lowered estimate, as it assumes that there is no unused lands, lakes, rivers or forests between the villages.
So, we have now an area of 3000 hectares. For the ease of calculation lets make this a perfectly circular area, what will result in a circle 6.18 km in diametre. To fortify such around the perimeter, one would need fortifications 19.4 km long. This is incidentally exactly 10 times more that the total length of wall encircling the old city of Dubrovnik or 8 time more than than the wall protecting Avila, both of which are considered the longest known European medieval city fortifications in existence. Even in China, fortifications of such magnitude were used to protect only largest cities (Beijing, Zhongdu, Chang'an or Nanjing) and remember, were speaking of a small, provincial town, not a seat of power or a major trading hub. It should also be noted that the sheer amount of time to build such fortification would have been immense - from the cost and time of raw material acquisition (stone or wood in case of brick walls has to be acquired, prepared and transported to the building site) to preparation of constituent elements (bricks or hewn stone) to actual construction. Assuming a stone wall 5 metres tall and 2 metres wide, then a 1 meter section of such wall would require 10 cubic meters of stone what would weigh roughly 27 tons meaning that the 19.4 km wall would require 523.800 tons of stone. Even a simple palisade made of tree trunks 4 metres in length (meaning the palisade itself would be at least a meter lower as the woods need to be dug in) and a 1 foot in diameter would weigh 0.7-0.9 tons per 1 metre section, depending on the wood used what would still amount to 18.000 tons of material. Then, the fortifications would have to be actually done by someone what would be quite hard, given that medieval peasants (vast majority of inhabitants of our hypothetical area) usually had quite a lot to do, especially between mid-spring and late autumn, so forcing them to build such massive fortification could have crippled the local economy, not to mention decreased food and raw material supply and very possible chance of a peasant uprising due to insane amount of work required by the lord.
The economic burden notwithstanding, said 19.4 km of fortifications would have to be defended, but with the population living inside the perimeter roughly equal to 3000 people, of which 20-25% were kids under 15 years of age and with half of population being women, usually not participating in direct combat this leaves us with 1200 men or 1 defender per 16 meters with at least part of them too old or sick to fight.
And last but not least, fortifications could do only so much against the opponents, given that even they could hamper incursion on the fields itself, they were not protecting it from enemy bombardment (until mid-14th century siege technology achieved its pre-gunpowder peak) and thus fields could have been easily devastated by the bombardment with ordinary or incendiary projectiles, rendering the whole idea of fortifying them less than reasonable.