When do divisors pull back? If we have a nonconstant map of nonsingular curves $\varphi:X\rightarrow Y$, then Hartshorne  defines a map $\varphi^* Div(Y)\rightarrow Div(X)$ using the fact that codimension one irreducibles are just points, and looking at $\mathcal{O}_{Y,f(p)} \rightarrow \mathcal{O}_{X,p}$. My question is if we don't have a nice map of curves, what conditions can we put on the morphism so that we may pull divisors back? Clearly it's not true in general, since we can take a constant map and then topologically the inverse image doesn't even have the right codim.
Thinking about this in terms of Cartier divisors (and assuming the schemes are integral), it seems like we just need a way to transport functions in $K(Y)$ to functions in $K(X)$. If $\varphi$ is dominant, then we'll get such a map. Is this sufficient? Also is there something we can say when $\varphi$ is not dominant? Something like we have a way to map divisors with support on $\overline{\varphi(X)}$ to divisors on $X$?
 A: Assume that both $X$ and $Y$ are locally noetherian and take a Cartier divisor $D$ on Y. I claim that $D$ pullbacks to a Cartier divisor on $X$ if and only if $f(Ass\ X) \cap |D|=\emptyset$.
Clearly this doesn't make sense unless I define what is a pullback of $D$: a Cartier divisor $E$ on $X$ is a pullback of $D$, written $E=f^*D$, if
1) $|E|\subseteq f^{-1}(|D|)$.
2) $U=X-f^{-1}(|D|)$ is schematically dense, i.e. $Ass\ X \subseteq U$, and there exists an isomorphism $\phi : f^*\mathcal{O}_Y(D)\longrightarrow \mathcal{O}_X(E)$ such that $\phi(f^*1)=1$ on $U$.
Condition $1)$ relates the supports $|D|$ and $|f^* D|$ while condition $2)$ states that $f^*\mathcal{O}_Y(D)\simeq \mathcal{O}_X(f^* D)$ and assures that $f^* D$ is uniquely determined.
The idea behind the above definition is that if $\mathcal{L}$ is an invertible sheaf on a scheme $X$ then $\mathcal{L}\simeq \mathcal{O}_X(E)$ for a Cartier divisor $E$ if and only if there exists a schematically dense open subset $U\subseteq X$ and a nowhere zero section $s\in \mathcal{L}(U)$. Moreover given $(U,s)$ there exists a unique $E$ s.t. $|E|\cap U = \emptyset$ and there exists an isomorphism $\mathcal{L}\simeq \mathcal{O}_X(E)$ sending $s$ to $1$ on $U$. Note that in general if $C$ is a divisor $X-|C|$ is schematically dense and $1$ is a nowhere zero section of $\mathcal{O}_X(C)$ on it.
In our case $f(Ass\ X) \cap |D|=\emptyset$ means that $U=X-f^{-1}(|D|)$ is schematically dense. Since $f^* 1$ is a nowhere zero section of $f^*\mathcal{O}_Y(D)$ over $U$ we obtain a divisor $f^*D$ satisfying conditions $1),2)$.
For example if $f(Ass\ X) \subseteq Ass Y$ you can pullback any Cartier divisor on $Y$. This happens if $f$ is flat or a dominant map between integral schemes.
Finally if $D$ is effective $f^*D$ exists, i.e. $f(Ass\ X) \cap |D|=\emptyset$, if and only if $f^{-1}(D)$ is an effective divisor and in this case they coincide. Moreover the exact sequence defining $D$ on $Y$ pullbacks to the exact sequence defining $f^{-1}(D)$ on $X$, which is very useful. (For the effective case see [Stacks project, 22.3]).
A: If you want to pull back a Cartier divisor $D$, you can do that provided the image of $f$ is not contained in the support of $D$: just pull back the local equations for $D$.
If this does not happen, on an integral scheme, you can just pass to the associated line bundle $\mathcal{O}_X(D)$ and pull back that, obtaining $f^{*} \mathcal{O}_X(D)$; of course you lose some information because a line bundle determines a Cartier divisor only up to linear equivalence.
Fulton invented a nice way to avoid this distinction. Define a pseudodivisor on $X$ to be a triple $(Z, L, s)$ where $Z$ is a closed subset of $X$, $L$ a line bundle and $s$ a nowhere vanishing section on $X \setminus Z$, hence a trivialization on that open set. Then you can simply define the pullback of this triple as $(f^{-1}(Z), f^{*} L, f^{*} s)$, so you can always pull back pseudo divisors, whatever $f$ is.
The relation with Cartier divisors is the following: to a Cartier divisor $D$ you can associate a pseudodivisor $(|D|, \mathcal{O}_X(D), s)$, where $s$ is the section of $\mathcal{O}_X(D)$ which gives a local equation for $D$.
This correspondence is not bijective. First, a pseudodivisor $(Z, L, s)$ determines a Cartier divisor if $Z \subsetneq X$; note that in this case enlarging $Z$ will not change the associated Cartier divisor, so to obtain a bijective correspondence with Cartier divisors you have to factor out pseudodivisors by an equivalence relation, which I leave to you to formulate. But if $Z = X$, you only obtain a line bundle on $X$, and you have no way to get back a Cartier divisor.
If you want to know more about this, read the second chapter of Fulton's intersection theory.
A: It seems to me that you are approaching this in the wrong way.
First of all you have to decide whether you want to pull-back      

divisors

or

divisor classes

Pulling back divisors means pulling back cycles and you run into all sorts of problems. If your map is flat, then this is OK. See Fulton's Intersection theory book for more on this. (There is a section called "flat pull-back of cycles" somewhere early). This is actually why Hartshorne did not have to worry about pulling back divisors or divisor classes. Any non-constant morphism between non-singular curves is flat. Of course, I am not saying this is the most general condition under which you can pull-back divisors, just that this is the "natural" one. Then again, this is a little too much, because it works for any dimensional cycles, not just divisors.
Pulling back divisor classes is somewhat easier (and harder at the same time). It is easier, because then you don't have to worry about the support. As already pointed out by Frank, you just "convert" your divisor class to a line bundle, pull that back and "convert" it back to a Cartier divisor. Actually for this you need $X$ to be integral, but you seem to be OK with assuming that.
Anyway, another, perhaps more interesting question is how to pull-back Weil divisors. The main problem there is that they are not defined locally by a single equation, so their associated sheaf
 is not an line bundle, only a reflexive sheaf of rank $1$. Unfortunately pulling back those does not necessarily give you a reflexive sheaf. One solution is to still do that and then take the reflexive hull, but this will likely not give a group homomorphism. Another partial way to handle Weil divisors is to restrict to $\mathbb Q$-Cartier divisors, i.e., a divisor that itself may not be Cartier, but a multiple of which is Cartier. Then you just take that multiple, pull that back and then divide by the same number you multiplied with. Interestingly this can result in fractional coefficients, so it will only preserve linear equivalence mod $\mathbb Q$. The simplest example of a $\mathbb Q$-Cartier, but not Cartier divisor is a ruling of a quadratic cone (look at intersection numbers to prove this). A little more interesting example is included in this MO answer. For an example of a non-$\mathbb Q$-Cartier divisor consider the cone over a quadric surface in $\mathbb P^3$ and let the divisor be the cone over one line on the surface.
A: If you have a morphism $f:X\rightarrow Y$ of schemes and $D$ is a Cartier divisor on $Y$, then you can pull back the invertible sheaf $\mathcal{O}(D)$ to $X$ and it will be an invertible subsheaf of the sheaf of total quotients $\mathcal{K}_X$. This sheaf defines a linear equivalence class of Cartier divisors but there's no clear choice of a specific divisor. If however you furthermore assume that $X$ is reduced, and $D$ is given by sections $f_i$ on an open covering $U_i$ of $Y$ whose support doesn't contain the image of any of the irreducible components of $X$, then you can define a Cartier divisor $f^*D$ on $X$ as $(f^{-1}(U_i), f_i\circ f)$ and this lies in the class of $f^*\mathcal{O}(D)$. This kind of "support-avoidance" is quite common with these arguments.
A: You shouldn't need to worry about whether or not the support intersects the closure $\overline{\varphi(X)}$. If it isn't, then your divisor simply pulls back to the zero divisor on X.
