If you want to use mipmapping, then the texture minifying function has to be GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR or GL_LINEAR_MIPMAP_LINEAR:
(See glTexParameter)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glGenerateMipmap(GL_TEXTURE_2D);
Note, glGenerateMipmap generates the mipmaps anyway. If the texture minifying is GL_NEAREST or GL_LINEAR, then the mipmaps are "ignored" on texture lookup.
If the minifying function is GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR or GL_LINEAR_MIPMAP_LINEAR and no mipmaps are generated, then the texture is not mipmap complete and texture access will return (0.0, 0.0, 0.0, 1.0), in the shader program.