Previous derivation of the Thouless-Anderson-Palmer (TAP) equations for the Hopfield model by the cavity method yielded results that were inconsistent with those of the perturbation theory as well as the results derived by the replica theory of the model. Here we present a derivation of the TAP equation for the Hopfield model by the cavity method and show that it agrees with the form derived by perturbation theory. We also use the cavity method to derive TAP equations for the pseudoinverse neural network model. These equations are consistent with the results of the replica theory of these models.