Let $Z$ and $Y$ be complex analytic spaces, and let $p : Z \to Y$ be a surjective proper morphism, which is flat. Let $\mathcal{F}$ be a coherent sheaf on $Z$, flat over $Y$, whose restriction to each fibre $p^{-1}(y)$ of the morphism is an invertible sheaf. Does this imply that $\mathcal{F}$ itself is invertible (i.e. locally free of rank 1) as a sheaf on $Z$? More generally, if $\mathcal{F}$ is locally free on the fibres, does it imply that it is locally free on the total space $Z$?
If this does not hold in full generality, what about the special case when $Z = X \times Y$, where $X$ is a compact complex manifold, and $p : X \times Y \to Y$ is the usual projection?