Constraint programming offers a declarative approach to solving problems modeled as constraint satisfaction problems (CSPs). However, the precise specification of a set of constraints is sometimes not available, but may have to be learned, for instance, from a set of examples of its solutions and non-solutions. In general, one may wish to learn generalized CSPs involving classical, fuzzy, weighted or probabilistic constraints, for example. This paper introduces a unifying framework for CSP learning. The framework is generic in that it can be instantiated to obtain specific formulations for learning classical, fuzzy, weighted or probabilistic CSPs. In particular, a new formulation for classical CSP learning, which minimizes the number of examples violated by candidate CSPs, is obtained by instantiating the framework. This formulation is equivalent to a simple pseudo-Boolean optimization problem, thus being efficiently solvable using many optimization tools..