First of all, we will assume the action is the integral of a local Lagrangian that only depends up to the first derivative of the fields. The analysis of more general cases, while possible is more complicated. When going over to the Hamiltonian formalism, we find there are constraints. Recall that in the action formalism, there are on shell and off shell configurations. The constraints that hold off shell are called primary constraints while those that only hold on shell are called secondary constraints.