We investigate the existence of a metallicity threshold for the production of long gamma-ray bursts (LGRBs). We used the host galaxies of the Swift/BAT6 sample of LGRBs. We considered the stellar mass, star formation rate (SFR), and metallicity determined from the host galaxy photometry and spectroscopy up to z = 2 and used them to compare the distribution of host galaxies to that of field galaxies in the mass-metallicity and fundamental metallicity relation plane. We find that although LGRBs also form in galaxies with relatively large stellar masses, the large majority of host galaxies have metallicities below log(O=H)~8.6. The extension to z = 2 results in a good sampling of stellar masses also above Log(Mstar/Msun)~9.5 and provides evidence that LGRB host galaxies do not follow the fundamental metallicity relation. As shown by the comparison with dedicated numerical simulations of LGRB host galaxy population, these results are naturally explained by the existence of a mild (~0.7 Zsun) threshold for the LGRB formation. The present statistics does not allow us to discriminate between different shapes of the metallicity cutoff, but the relatively high metallicity threshold found in this work is somewhat in disagreement to most of the standard single-star models for LGRB progenitors.