apache/cassandra · error · InvalidConstraintDefinitionException
There are duplicate constraint definitions on column '%s': %
Error message
There are duplicate constraint definitions on column '%s': %s
What it means
ColumnConstraints.checkSatisfiability detects when the same constraint (same constraint name enabling duplicates) is defined more than once on a single column, which would be ambiguous or redundant. It throws InvalidConstraintDefinitionException listing the column and the duplicated constraint names. This is schema-definition-time validation.
Source
Thrown at src/java/org/apache/cassandra/cql3/constraints/ColumnConstraints.java:194
public void checkSatisfiability(List<ColumnConstraint<?>> constraints, ColumnMetadata columnMetadata)
{
Set<String> constraintNames = new TreeSet<>();
List<String> duplicateConstraints = new ArrayList<>();
for (ColumnConstraint<?> constraint : constraints)
{
String constraintFullName = constraint.fullName();
String constraintName = constraint.name();
if (!constraintNames.add(constraintFullName))
{
if (!constraint.enablesDuplicateDefinitions(constraintName))
duplicateConstraints.add(constraintFullName);
}
}
if (!duplicateConstraints.isEmpty())
throw new InvalidConstraintDefinitionException(format("There are duplicate constraint definitions on column '%s': %s",
columnMetadata.name,
duplicateConstraints));
}
}
private static class Noop extends ColumnConstraints
{
private Noop()
{
super(Collections.emptyList());
}
@Override
public void validate(ColumnMetadata columnMetadata)
{
// Do nothing. It is always valid
}
View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Remove the duplicate constraint so each constraint appears once per column.
- Merge duplicate constraints into a single one covering all needed checks (e.g. combine length bounds into one range).
- Use a constraint implementation whose enablesDuplicateDefinitions() returns true if multiple instances are intentional.
Example fix
// before name text CONSTRAINT CHECK LENGTH(1..10) CONSTRAINT CHECK LENGTH(1..20) // after name text CONSTRAINT CHECK LENGTH(1..20)
Defensive patterns
Strategy: validation
Validate before calling
Map<String,Integer> counts = new HashMap<>();
for (ColumnConstraint<?> c : constraints)
counts.merge(c.name(), 1, Integer::sum);
if (counts.values().stream().anyMatch(n -> n > 1)) throw new IllegalStateException("duplicate constraint definitions"); Prevention
- Deduplicate constraint lists in schema-builder code
- Idempotent migration scripts: check for existing constraint before adding
- Review hand-edited DDL for repeated CHECK clauses
When it happens
Trigger: A CREATE TABLE / ALTER TABLE statement specifies two constraints of the same kind on one column where the constraint's enablesDuplicateDefinitions() returns false — e.g. two identical LENGTH or JSON constraints on the same column.
Common situations: Hand-written DDL that repeats a constraint; schema migration scripts that re-add a constraint already present; generated DDL merging constraint lists without deduplication.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Constraint '%s' can be used only for columns of type %s but
- Constraint cannot be defined on the column <name> of type <t
- Constraint %s was not specified on a column it operates on:
- Constraint %s does not accept any arguments.
- %s constraint can not be specified on a %s key column '%s'
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/369d22785f764082.
Report an issue: GitHub.