hcju/stacksqa huggingface dataset:
During the proof we may replace $X$ by an open neighbourhood of $x$ and we may replace $S$ by an elementary \'etale neighbourhood of $s$. Hence, by openness of flatness (see More on Morphisms, Theorem \ref{more-morphisms-theorem-openness-flatness}) we may assume that $\mathcal{F}$ is flat over $S$. We may assume $S$ and $X$ are affine. After shrinking $X$ some more we may assume that any point of $\text{Ass}_{X_s}(\mathcal{F}_s)$ is a generalization of $x$. This property is preserved on replacing $(S, s)$ by an elementary \'etale neighbourhood. Hence we may apply Lemma \ref{lemma-finite-presentation-flat-along-fibre} to arrive at the situation where there exists a diagram $$ \xymatrix{ X \ar[dr] & & X' \ar[ll]^g \ar[ld] \\ & S & } $$ of schemes affine and of finite presentation over $S$, where $g$ is \'etale, $X_s \subset g(X')$, and with $\Gamma(X', g^*\mathcal{F})$ a projective $\Gamma(S, \mathcal{O}_S)$-module. Note that in this case $g^*\mathcal{F}$ is universally pure over $S$, see Lemma \ref{lemma-affine-locally-projective-pure}. \medskip\noindent Let $U \subset g(X')$ be an affine open neighbourhood of $x$. We claim that $\mathcal{F}|_U$ is pure along $U_s$. If we prove this, then the lemma follows because $\mathcal{F}|_U$ will be pure relative to $S$ after shrinking $S$, see Lemma \ref{lemma-flat-finite-presentation-purity-open}, whereupon the projectivity follows from Proposition \ref{proposition-finite-presentation-flat-pure-is-projective}. To prove the claim we have to show, after replacing $(S, s)$ by an arbitrary elementary \'etale neighbourhood, that any point $\xi$ of $\text{Ass}_{U/S}(\mathcal{F}|_U)$ lying over some $s' \in S$, $s' \leadsto s$ specializes to a point of $U_s$. Since $U \subset g(X')$ we can find a $\xi' \in X'$ with $g(\xi') = \xi$. Because $g^*\mathcal{F}$ is pure over $S$, using Lemma \ref{lemma-associated-point-specializes}, we see there exists a specialization $\xi' \leadsto x'$ with $x' \in \text{Ass}_{X'_s}(g^*\mathcal{F}_s)$. Then $g(x') \in \text{Ass}_{X_s}(\mathcal{F}_s)$ (see for example Lemma \ref{lemma-etale-weak-assassin-up-down} applied to the \'etale morphism $X'_s \to X_s$ of Noetherian schemes) and hence $g(x') \leadsto x$ by our choice of $X$ above! Since $x \in U$ we conclude that $g(x') \in U$. Thus $\xi = g(\xi') \leadsto g(x') \in U_s$ as desired.
The question is Zariski local on $X$ and $S$. Hence we may assume that $X$ and $S$ are affine. Then we can find a closed immersion $i : X \to \mathbf{A}^n_S$ over $S$. It is clear that it suffices to prove the lemma for the sheaf $i_*\mathcal{F}$ on $\mathbf{A}^n_S$ and the point $i(x)$. In this way we reduce to the case where $X \to S$ is of finite presentation. After replacing $S$ by $\Spec(\mathcal{O}_{S', s'})$ and $X$ by an open of $X \times_S \Spec(\mathcal{O}_{S', s'})$ we may assume that $\mathcal{F}$ is of finite presentation, see Proposition \ref{proposition-finite-type-flat-at-point}. In this case we may appeal to Lemma \ref{lemma-flat-finite-presentation-affine-neighbourhood-projective} and Algebra, Theorem \ref{algebra-theorem-projective-free-over-local-ring} to conclude.
We can find a morphism of finite type $X \to S = \Spec(A)$ and a point $x \in X$ lying over the closed point $s$ of $S$ and a finite type quasi-coherent $\mathcal{O}_X$-module $\mathcal{F}$ such that $\mathcal{F}_x \cong N$ as an $A$-module. After shrinking $X$ we may assume that each point of $\text{Ass}_{X_s}(\mathcal{F}_s)$ specializes to $x$. By Lemma \ref{lemma-flat-finite-type-affine-neighbourhood-projective} we see that there exists a fundamental system of affine open neighbourhoods $U_i \subset X$ of $x$ such that $\Gamma(U_i, \mathcal{F})$ is a free $A$-module $F_i$. Note that if $U_{i'} \subset U_i$, then $$ F_i/\mathfrak m_AF_i = \Gamma(U_{i, s}, \mathcal{F}_s) \longrightarrow \Gamma(U_{i', s}, \mathcal{F}_s) = F_{i'}/\mathfrak m_AF_{i'} $$ is injective because a section of the kernel would be supported at a closed subset of $X_s$ not meeting $x$ which is a contradiction to our choice of $X$ above. Since the maps $F_i \to F_{i'}$ are $A$-universally injective (Lemma \ref{lemma-universally-injective-local}) it follows that $N$ is Mittag-Leffler by Algebra, Lemma \ref{algebra-lemma-colimit-universally-injective-ML}.
Let $A \subset A^h$ be the henselization. Let $B'$ be the localization of $B \otimes_A A^h$ at the maximal ideal $\mathfrak m_B \otimes A^h + B \otimes \mathfrak m_{A^h}$. Then $B \to B'$ is flat, hence faithfully flat. Let $N' = N \otimes_B B'$. Let $x \in N$ and let $x' \in N'$ be the image. We claim that for an ideal $I \subset A$ we have $x \in IN \Leftrightarrow x' \in IN'$. Namely, $N/IN \to N'/IN'$ is the tensor product of $B \to B'$ with $N/IN$ and $B \to B'$ is universally injective by Algebra, Lemma \ref{algebra-lemma-faithfully-flat-universally-injective}. By More on Algebra, Lemma \ref{more-algebra-lemma-henselization-valuation-ring} and Algebra, Lemma \ref{algebra-lemma-ideals-valuation-ring} the map $A \to A^h$ defines an inclusion preserving bijection $I \mapsto IA^h$ on sets of ideals. We conclude that $x$ has a content ideal in $A$ if and only if $x'$ has a content ideal in $A^h$. The assertion for $x' \in N'$ follows from Lemma \ref{lemma-flat-finite-type-local-colimit-free} and Algebra, Lemma \ref{algebra-lemma-minimal-contains}.
Let $A'$ be an object of $\mathcal{C}$. Set $C' = C \otimes_A A'$ and $N' = N \otimes_A A'$ similarly to the definitions of $B'$, $M'$ in Situation \ref{situation-flat-at-point}. Note that $M' \cong N'$ as $B'$-modules. The assumption that $B \to C$ is finite has two consequences: (a) $\mathfrak m_C = \sqrt{\mathfrak m_B C}$ and (b) $B' \to C'$ is finite. Consequence (a) implies that $$ V(\mathfrak m_{A'}C' + \mathfrak m_C C') = \left( \Spec(C') \to \Spec(B') \right)^{-1}V(\mathfrak m_{A'}B' + \mathfrak m_B B'). $$ Suppose $\mathfrak q \subset V(\mathfrak m_{A'}B' + \mathfrak m_B B')$. Then $M'_{\mathfrak q}$ is flat over $A'$ if and only if the $C'_{\mathfrak q}$-module $N'_{\mathfrak q}$ is flat over $A'$ (because these are isomorphic as $A'$-modules) if and only if for every maximal ideal $\mathfrak r$ of $C'_{\mathfrak q}$ the module $N'_{\mathfrak r}$ is flat over $A'$ (see Algebra, Lemma \ref{algebra-lemma-flat-localization}). As $B'_{\mathfrak q} \to C'_{\mathfrak q}$ is finite by (b), the maximal ideals of $C'_{\mathfrak q}$ correspond exactly to the primes of $C'$ lying over $\mathfrak q$ (see Algebra, Lemma \ref{algebra-lemma-integral-going-up}) and these primes are all contained in $V(\mathfrak m_{A'}C' + \mathfrak m_C C')$ by the displayed equation above. Thus the result of the lemma holds.
Let $A'$ be an object of $\mathcal{C}$. Set $C' = C \otimes_A A'$ and $N' = N \otimes_A A' = M' \otimes_{B'} C'$ similarly to the definitions of $B'$, $M'$ in Situation \ref{situation-flat-at-point}. Note that $$ V(\mathfrak m_{A'}B' + \mathfrak m_B B') = \Spec( \kappa(\mathfrak m_B) \otimes_A \kappa(\mathfrak m_{A'}) ) $$ and similarly for $V(\mathfrak m_{A'}C' + \mathfrak m_C C')$. The ring map $$ \kappa(\mathfrak m_B) \otimes_A \kappa(\mathfrak m_{A'}) \longrightarrow \kappa(\mathfrak m_C) \otimes_A \kappa(\mathfrak m_{A'}) $$ is faithfully flat, hence $V(\mathfrak m_{A'}C' + \mathfrak m_C C') \to V(\mathfrak m_{A'}B' + \mathfrak m_B B')$ is surjective. Finally, if $\mathfrak r \in V(\mathfrak m_{A'}C' + \mathfrak m_C C')$ maps to $\mathfrak q \in V(\mathfrak m_{A'}B' + \mathfrak m_B B')$, then $M'_{\mathfrak q}$ is flat over $A'$ if and only if $N'_{\mathfrak r}$ is flat over $A'$ because $B' \to C'$ is flat, see Algebra, Lemma \ref{algebra-lemma-flatness-descends-more-general}. The lemma follows formally from these remarks.
Let $x \in X$ be a point over $s \in S$. Then the dimension of the closure of $\{x\}$ in $X_s$ is $\text{trdeg}_{\kappa(s)}(\kappa(x))$ by Varieties, Lemma \ref{varieties-lemma-dimension-locally-algebraic}. Conversely, if $Z \subset X_s$ is a closed subset of dimension $d$, then there exists a point $x \in Z$ with $\text{trdeg}_{\kappa(s)}(\kappa(x)) = d$ (same reference). Therefore the equivalence of (1) and (2) holds (even fibre by fibre). The statement on base change follows from Morphisms, Lemmas \ref{morphisms-lemma-base-change-module-flat} and \ref{morphisms-lemma-dimension-fibre-after-base-change}.
Part (1) follows from the following statement: If $T' \to T$ is a surjective flat morphism of schemes over $S$, then $\mathcal{F}_{T'}$ is flat over $T'$ if and only if $\mathcal{F}_T$ is flat over $T$, see More on Morphisms, Lemma \ref{more-morphisms-lemma-flat-locus-base-change}. Part (2) follows from Limits, Lemma \ref{limits-lemma-descend-module-flat-finite-presentation} after reducing to the case where $X$ and $S$ are affine (compare with the proof of Lemma \ref{lemma-flat-dimension-n}).
We can find a cartesian diagram $$ \xymatrix{ X \ar[d] \ar[r] & X_0 \ar[d] \\ S \ar[r] & S_0 } $$ and a finitely presented $\mathcal{O}_{X_0}$-module $\mathcal{F}_0$ which pulls back to $\mathcal{F}$ such that $X_0$ and $S_0$ are of finite type over $\mathbf{Z}$. See Limits, Proposition \ref{limits-proposition-approximate} and Lemmas \ref{limits-lemma-descend-finite-presentation} and \ref{limits-lemma-descend-modules-finite-presentation}. Thus we may assume $X$ and $S$ are of finite type over $\mathbf{Z}$ and $\mathcal{F}$ is a coherent $\mathcal{O}_X$-module. \medskip\noindent Assume $X$ and $S$ are of finite type over $\mathbf{Z}$ and $\mathcal{F}$ is a coherent $\mathcal{O}_X$-module. In this case every quasi-coherent ideal is of finite type, hence we do not have to check the condition that $S_i$ is cut out by a finite type ideal. Set $S_0 = S_{red}$ equal to the reduction of $S$. By generic flatness as stated in Morphisms, Proposition \ref{morphisms-proposition-generic-flatness-reduced} there is a dense open $U_0 \subset S_0$ such that $\mathcal{F}$ pulled back to $X \times_S U_0$ is flat over $U_0$. Let $S_1 \subset S_0$ be the reduced closed subscheme whose underlying closed subset is $S \setminus U_0$. We continue in this way, provided $S_1 \not = \emptyset$, to find $S_0 \supset S_1 \supset \ldots$. Because $S$ is Noetherian any descending chain of closed subsets stabilizes hence we see that $S_t = \emptyset$ for some $t \geq 0$.
Choose an affine open covering $X = \bigcup U_i$. Then $F_{flat}$ is the product of the functors associated to each of the pairs $(U_i, \mathcal{F}|_{U_i})$. Hence it suffices to prove the result for each $(U_i, \mathcal{F}|_{U_i})$. In the affine case the lemma follows immediately from More on Algebra, Lemma \ref{more-algebra-lemma-flattening-artinian-universal-property}.
The final assertion means that $\mathcal{F}_T \to (g_T)_*g_T^*\mathcal{F}_T$ is injective for any morphism $T \to S$. The assumption $\text{Ass}_{X/S}(\mathcal{F}) \subset g(X')$ is preserved by base change, see Divisors, Lemma \ref{divisors-lemma-base-change-relative-assassin} and Remark \ref{divisors-remark-base-change-relative-assassin}. The same holds for the assumption of flatness and finite type. Hence it suffices to prove the injectivity of the displayed arrow. Let $\mathcal{K} = \Ker(\mathcal{F} \to g_*g^*\mathcal{F})$. Our goal is to prove that $\mathcal{K} = 0$. In order to do this it suffices to prove that $\text{WeakAss}_X(\mathcal{K}) = \emptyset$, see Divisors, Lemma \ref{divisors-lemma-weakly-ass-zero}. We have $\text{WeakAss}_X(\mathcal{K}) \subset \text{WeakAss}_X(\mathcal{F})$, see Divisors, Lemma \ref{divisors-lemma-ses-weakly-ass}. As $\mathcal{F}$ is flat we see from Lemma \ref{lemma-bourbaki-finite-type-general-base} that $\text{WeakAss}_X(\mathcal{F}) \subset \text{Ass}_{X/S}(\mathcal{F})$. By assumption any point $x$ of $\text{Ass}_{X/S}(\mathcal{F})$ is the image of some $x' \in X'$. Since $g$ is flat the local ring map $\mathcal{O}_{X, x} \to \mathcal{O}_{X', x'}$ is faithfully flat, hence the map $$ \mathcal{F}_x \longrightarrow g^*\mathcal{F}_{x'} = \mathcal{F}_x \otimes_{\mathcal{O}_{X, x}} \mathcal{O}_{X', x'} $$ is injective (see Algebra, Lemma \ref{algebra-lemma-faithfully-flat-universally-injective}). This implies that $\mathcal{K}_x = 0$ as desired.
Let $\mathcal{I}$ be the ideal sheaf defining $Y$ in $X$ and let $u:\mathcal{O}_X\to\mathcal{O}_X/\mathcal{I}$ be the surjection. Then for an $S$-scheme $T$, the closed immersion $Y_T\to X_T$ is an isomorphism if and only if $u_T$ is an isomorphism. Hence the result follows from Theorem \ref{theorem-flattening-map}.
For $x \in X_s$ denote $Z_x \subset S$ the closed subscheme we found in Remark \ref{remark-flattening-local-scheme-theoretic}. Then it is clear that $Z = \bigcap_{x \in E} Z_x$ works! \medskip\noindent To prove the final statement assume $X$ locally of finite presentation, $\mathcal{F}$ of finite presentation and $Z$ closed and quasi-compact. First, choose finitely many affine opens $W_j \subset X$ such that $E \subset \bigcup W_j$. It clearly suffices to prove the result for each morphism $W_j \to S$ with sheaf $\mathcal{F}|_{X_j}$ and closed subset $E \cap W_j$. Hence we may assume $X$ is affine. In this case, More on Algebra, Lemma \ref{more-algebra-lemma-limit-preserving-flat-at-primes} shows that the functor defined by (1) is ``limit preserving''. Hence we can show that $Z \to S$ is of finite presentation exactly as in the last part of the proof of Theorem \ref{theorem-flattening-local}.
Applying Algebra, Lemma \ref{algebra-lemma-mod-injective} we see that $u$ is injective and that $N/u(M)$ is flat over $A$. Then $u$ is $A$-universally injective (Algebra, Lemma \ref{algebra-lemma-flat-tor-zero}) and $N$ is $A$-flat (Algebra, Lemma \ref{algebra-lemma-flat-ses}). Since $B$ is Noetherian in this case we see that $N$ is of finite presentation.
Let $A \to B$, $u : N \to M$ be as in Situation \ref{situation-mod-injective}. Write $B = C/I$ where $C$ is the localization of a polynomial algebra over $A$ at a prime. If we can show that $N$ is finitely presented as a $C$-module, then a fortiori this shows that $N$ is finitely presented as a $B$-module (see Algebra, Lemma \ref{algebra-lemma-finitely-presented-over-subring}). Hence we may assume that $B$ is the localization of a polynomial algebra. Next, write $N = B^{\oplus n}/K$ for some submodule $K \subset B^{\oplus n}$. Since $B/\mathfrak m_AB$ is Noetherian (as it is essentially of finite type over a field), there exist finitely many elements $k_1, \ldots, k_s \in K$ such that for $K' = \sum Bk_i$ and $N' = B^{\oplus n}/K'$ the canonical surjection $N' \to N$ induces an isomorphism $N'/\mathfrak m_AN' \cong N/\mathfrak m_AN$. Now, if the lemma holds for the composition $u' : N' \to M$, then $u'$ is injective, hence $N' = N$ and $u' = u$. Thus the lemma holds for the original situation.
It suffices to prove this when $B$ is essentially of finite presentation over $A$ and $N$ is of finite presentation over $B$, see Lemma \ref{lemma-reduce-finite-type-injective-into-flat-mod-m}. Let us temporarily make the additional assumption that $N$ is flat over $A$. Then $N$ is a filtered colimit $N = \colim_i F_i$ of free $A$-modules $F_i$ such that the transition maps $u_{ii'} : F_i \to F_{i'}$ are injective modulo $\mathfrak m_A$, see Lemma \ref{lemma-flat-finite-type-local-colimit-free}. Each of the compositions $u_i : F_i \to M$ is $A$-universally injective by Lemma \ref{lemma-universally-injective-local} wherefore $u = \colim u_i$ is $A$-universally injective as desired. \medskip\noindent Assume $A$ is a henselian local ring, $B$ is essentially of finite presentation over $A$, $N$ of finite presentation over $B$. By Theorem \ref{theorem-flattening-local} there exists a finitely generated ideal $I \subset A$ such that $N/IN$ is flat over $A/I$ and such that $N/I^2N$ is not flat over $A/I^2$ unless $I = 0$. The result of the previous paragraph shows that the lemma holds for $u \bmod I : N/IN \to M/IM$ over $A/I$. Consider the commutative diagram $$ \xymatrix{ 0 \ar[r] & M \otimes_A I/I^2 \ar[r] & M/I^2M \ar[r] & M/IM \ar[r] & 0 \\ & N \otimes_A I/I^2 \ar[r] \ar[u]^u & N/I^2N \ar[r] \ar[u]^u & N/IN \ar[r] \ar[u]^u & 0 } $$ whose rows are exact by right exactness of $\otimes$ and the fact that $M$ is flat over $A$. Note that the left vertical arrow is the map $N/IN \otimes_{A/I} I/I^2 \to M/IM \otimes_{A/I} I/I^2$, hence is injective. A diagram chase shows that the lower left arrow is injective, i.e., $\text{Tor}^1_{A/I^2}(I/I^2, M/I^2) = 0$ see Algebra, Remark \ref{algebra-remark-Tor-ring-mod-ideal}. Hence $N/I^2N$ is flat over $A/I^2$ by Algebra, Lemma \ref{algebra-lemma-what-does-it-mean} a contradiction unless $I = 0$.
Let $A \to A^h$ be the henselization of $A$. Let $B'$ be the localization of $B \otimes_A A^h$ at the maximal ideal $\mathfrak m_B \otimes A^h + B \otimes \mathfrak m_{A^h}$. Since $B \to B'$ is flat (hence faithfully flat, see Algebra, Lemma \ref{algebra-lemma-local-flat-ff}), we may replace $A \to B$ with $A^h \to B'$, the module $M$ by $M \otimes_B B'$, the module $N$ by $N \otimes_B B'$, and $u$ by $u \otimes \text{id}_{B'}$, see Algebra, Lemmas \ref{algebra-lemma-descend-properties-modules} and \ref{algebra-lemma-flatness-descends-more-general}. Thus we may assume that $A$ is a henselian local ring. In this case our lemma follows from the more general Lemma \ref{lemma-henselian-finite-type-injective-into-flat-mod-m}.
Recall that an $A$-module is flat if and only if it is torsion free, see More on Algebra, Lemma \ref{more-algebra-lemma-valuation-ring-torsion-free-flat}. Let $T \subset N$ be the $A$-torsion. Then $u(T) = 0$ and $N/T$ is $A$-flat. Hence $N/T$ is finitely presented over $B$, see More on Algebra, Lemma \ref{more-algebra-lemma-flat-finite-type-valuation-ring-finite-presentation}. Thus $T$ is a finite $B$-module, see Algebra, Lemma \ref{algebra-lemma-extension}. Since $N/T$ is $A$-flat we see that $T/\mathfrak m_A T \subset N/\mathfrak m_A N$, see Algebra, Lemma \ref{algebra-lemma-flat-tor-zero}. As $\overline{u}$ is injective but $u(T) = 0$, we conclude that $T/\mathfrak m_A T = 0$. Hence $T = 0$ by Nakayama's lemma, see Algebra, Lemma \ref{algebra-lemma-NAK}. At this point we have proved two out of the three assertions ($N$ is $A$-flat and of finite presentation over $B$) and what is left is to show that $u$ is universally injective. \medskip\noindent By Algebra, Theorem \ref{algebra-theorem-universally-exact-criteria} it suffices to show that $N \otimes_A Q \to M \otimes_A Q$ is injective for every finitely presented $A$-module $Q$. By More on Algebra, Lemma \ref{more-algebra-lemma-generalized-valuation-ring-modules} we may assume $Q = A/(a)$ with $a \in \mathfrak m_A$ nonzero. Thus it suffices to show that $N/aN \to M/aM$ is injective. Let $x \in N$ with $u(x) \in aM$. By Lemma \ref{lemma-flat-finite-type-local-valuation-ring-has-content} we know that $x$ has a content ideal $I \subset A$. Since $I$ is finitely generated (More on Algebra, Lemma \ref{more-algebra-lemma-content-finitely-generated}) and $A$ is a valuation ring, we have $I = (b)$ for some $b$ (by Algebra, Lemma \ref{algebra-lemma-characterize-valuation-ring}). By More on Algebra, Lemma \ref{more-algebra-lemma-equal-content} the element $u(x)$ has content ideal $I$ as well. Since $u(x) \in aM$ we see that $(b) \subset (a)$ by More on Algebra, Definition \ref{more-algebra-definition-content-ideal}. Since $x \in bN$ we conclude $x \in aN$ as desired.
Choose $U$, $N'$ as in the definition of a pure spreadout. Any element $x' \in N'$ has a content ideal in $A$ because $N'$ is $A$-projective (this can easily be seen directly, but it also follows from More on Algebra, Lemma \ref{more-algebra-lemma-content-exists-flat-Mittag-Leffler} and Algebra, Example \ref{algebra-example-ML}). Since $N' \to N$ is $A$-universally injective, we see that the image $x \in N$ of any $x' \in N'$ has a content ideal in $A$ (it is the same as the content ideal of $x'$). For a general $x \in N$ we choose $s \in S$ such that $s x$ is in the image of $N' \to N$ and we use that $x$ and $sx$ have the same content ideal. \medskip\noindent Let $u : N \to M$ be as in (2). To show that $u$ is $A$-universally injective, we may replace $A$ by a localization at a maximal ideal (small detail omitted). Assume $A$ is local with maximal ideal $\mathfrak m$. Pick $s \in S$ and consider the composition $$ N' \to N \xrightarrow{1/s} N \xrightarrow{u} M $$ Each of these maps is injective modulo $\mathfrak m$, hence the composition is $A$-universally injective by Lemma \ref{lemma-universally-injective-local}. Since $N = \colim_{s \in S} (1/s)N'$ we conclude that $u$ is $A$-inversally injective as a colimit of universally injective maps.
We may replace $A$ by $A_\mathfrak p$. Thus we may assume $A$ is local and $\mathfrak p$ is the maximal ideal $\mathfrak m$ of $A$. We may write $N = S^{-1}N'$ for some finitely presented $B$-module $N'$ by clearing denominators in a presentation of $N$ over $S^{-1}B$. Since $B/\mathfrak m B$ is Noetherian, the kernel $K$ of $N'/\mathfrak m N' \to N/\mathfrak m N$ is finitely generated. Thus we can pick $s \in S$ such that $K$ is annihilated by $s$. After replacing $B$ by $B_s$ which is allowed as it just means passing to an affine open subscheme of $\Spec(B)$, we find that the elements of $S$ are injective on $N'/\mathfrak m N'$. At this point we choose a local subring $A_0 \subset A$ essentially of finite type over $\mathbf{Z}$, a finite type ring map $A_0 \to B_0$ such that $B = A \otimes_{A_0} B_0$, and a finite $B_0$-module $N'_0$ such that $N' = B \otimes_{B_0} N'_0 = A \otimes_{A_0} N'_0$. We claim that $I = \mathfrak m_{A_0} A$ works. Namely, we have $$ N'/IN' = N'_0/\mathfrak m_{A_0} N'_0 \otimes_{\kappa_{A_0}} A/I $$ which is free over $A/I$. Multiplication by the elements of $S$ is injective after dividing out by the maximal ideal, hence $N'/IN' \to N/IN$ is universally injective for example by Lemma \ref{lemma-invert-universally-injective}.
By Algebra, Lemma \ref{algebra-lemma-check-universally-injective-into-flat} it suffices to check that $N/IN \to M/IM$ is injective for every ideal $I \subset A$. After replacing $A$ by $A/I$ we see that it suffices to prove that $u$ is injective. \medskip\noindent Proof that $u$ is injective. Let $x \in N$ be a nonzero element of the kernel of $u$. Then there exists a weakly associated prime $\mathfrak p$ of the module $Ax$, see Algebra, Lemma \ref{algebra-lemma-weakly-ass-zero}. Replacing $A$ by $A_\mathfrak p$ we may assume $A$ is local and we find a nonzero element $y \in Ax$ whose annihilator has radical equal to $\mathfrak m_A$, see Algebra, Lemma \ref{algebra-lemma-weakly-ass-local}. Thus $\text{Supp}(y) \subset \Spec(S^{-1}B)$ is nonempty and contained in the closed fibre of $\Spec(S^{-1}B) \to \Spec(A)$. Let $I \subset \mathfrak m_A$ be a finitely generated ideal so that we have a pure spreadout over $A/I$, see Lemma \ref{lemma-find-pure-spreadout}. Then $I^n y = 0$ for some $n$. Now $y \in \text{Ann}_M(I^n) = \text{Ann}_A(I^n) \otimes_R N$ by flatness. Thus, to get the desired contradiction, it suffices to show that $$ \text{Ann}_A(I^n) \otimes_R N \longrightarrow \text{Ann}_A(I^n) \otimes_R M $$ is injective. Since $N$ and $M$ are flat and since $\text{Ann}_A(I^n)$ is annihilated by $I^n$, it suffices to show that $Q \otimes_A N \to Q \otimes_A M$ is injective for every $A$-module $Q$ annihilated by $I$. This holds by our choice of $I$ and Lemma \ref{lemma-properties-pure-spreadout} part (2).
Since $\mathfrak m_A \subset A$ is not the generic point of $\Spec(A)$ we see that $I \subset \mathfrak m_A$ for at least one $I \in S$. Hence $\bigcap_{I \in S} I \subset \mathfrak m_A$. Let $f \in \mathfrak m_A$ be nonzero. Then $V(f) \subset \bigcup_{I \in S} V(I)$. Since the constructible topology on $V(f)$ is quasi-compact (Topology, Lemma \ref{topology-lemma-constructible-hausdorff-quasi-compact} and Algebra, Lemma \ref{algebra-lemma-spec-spectral}) we find that $V(f) \subset V(I_1) \cup \ldots \cup V(I_n)$ for some $I_j \in S$. Because $I_1 \ldots I_n \in S$ we see that $V(f) \subset V(I)$ for some $I$. As $I$ is finitely generated this implies that $I^m \subset (f)$ for some $m$ and since $S$ is closed under products we see that $I \subset (f^2)$ for some $I \in S$. Then it is not possible to have $f \in I$.