Michael Bayer () wrote:
hello -
unfortunately there is a hard to explain intent behind this behavior and neither the documentation at http://alembic.zzzcomputing.com/en/latest/naming.html nor at http://docs.sqlalchemy.org/en/latest/core/constraints.html#constraint-naming-conventions attempt to explain it, and this should be fixed.
The behavior of naming conventions is as follows:
-
if the constraint has a name of None
, then the naming convention is applied.
-
if the constraint name has a name of None
, and the naming convention includes the token %(constraint_name)s
, then an error is raised: "Naming convention including %(constraint_name)s token requires that constraint is explicitly named."
-
if the constraint has a non-None
name, and the convention does not include the %(constraint_name)s
token, then it is assumed that the constraint was given an explicit name, and the convention is not applied.
-
if the constraint has a non-None
name, and the convention includes the token %(constraint_name)s
, then it is assumed that this name is part of fulfillment of the contract of the convention, and the naming convention is applied, using the existing name for %(constraint_name)s
.
-
if the constraint has an f()
name, then no naming convention is applied ever.
Alembic autogeneration will always be generate operations using the f()
qualifier if they are based on a schema construct where a naming convention has already been applied. This was added in #183.
Above, we can see out of the five possible options, the case named in 3 is the only one which is ambiguous and is giving you problems. I has nothing to do with CHECK constraints. I would favor use case #3 emitting a warning, e.g. always use f() or None for a constraint name when naming convention is in place, though the impact of this warning would need to be carefully tested.