apache/cassandra · error · InvalidRequestException

Duplicate definition of NOT NULL constraint

Error message

Duplicate definition of NOT NULL constraint

What it means

A NOT NULL constraint was specified for a column that already carries a NOT NULL constraint in its prepared ColumnConstraints — either the column already has an explicit NOT NULL or the isNotNull flag is applied on top of constraints containing one. The builder rejects the redundant definition.

Solutions

  1. Remove the redundant NOT NULL specification, keeping only one
  2. Inspect the prepared ColumnConstraints before adding a NOT NULL (use containsNotNullConstraint())
  3. If constraints are built programmatically, guard with if (!constraints.containsNotNullConstraint())

Example fix

// before
col int NOT NULL, -- plus a NOT NULL check constraint from merged DDL
// after
col int NOT NULL,
Defensive patterns

Strategy: validation

Validate before calling

if (isNotNull && constraints.containsNotNullConstraint()) throw new Error('NOT NULL already present for column ' + column);

Try / catch

try { session.execute(ddl); } catch (e) { if (/Duplicate definition of NOT NULL/.test(e.message)) { /* strip one NOT NULL source and retry */ } else throw e; }

Prevention

When it happens

Trigger: Declaring a column with a NOT NULL constraint (e.g. via constraints syntax) and also passing isNotNull=true; repeating NOT NULL twice for the same column in DDL that supports constraint syntax.

Common situations: Generated DDL that adds NOT NULL both in a constraint list and as a column modifier; merging schema fragments that each contribute a NOT NULL for the same column.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/45c709769401b7e4. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java:636

        public String table()
        {
            return name.getName();
        }

        public void addColumn(ColumnIdentifier column, CQL3Type.Raw type, boolean isStatic, boolean isNotNull, ColumnMask.Raw mask, ColumnConstraints.Raw constraints)
        {
            if (null != rawColumns.put(column, new ColumnProperties.Raw(type, mask)))
                throw ire("Duplicate column '%s' declaration for table '%s'", column, name);

            if (isStatic)
                staticColumns.add(column);

            ColumnConstraints preparedConstraints = constraints == null ? ColumnConstraints.NO_OP : constraints.prepare(column);

            if (isNotNull)
            {
                 if (preparedConstraints.containsNotNullConstraint())
                     throw ire("Duplicate definition of NOT NULL constraint");

                List<ColumnConstraint<?>> checkConstraints = new ArrayList<>(preparedConstraints.getConstraints());
                checkConstraints.add(new UnaryFunctionColumnConstraint(new NotNullConstraint()));
                preparedConstraints = new ColumnConstraints(checkConstraints);
                preparedConstraints.setColumnName(column);
            }

            columnConstraints.put(column, preparedConstraints);
        }

        public void addColumn(ColumnIdentifier column, CQL3Type.Raw type, boolean isStatic, ColumnMask.Raw mask, ColumnConstraints.Raw constraints)
        {
            addColumn(column, type, isStatic, false, mask, constraints);
        }

        public void setCompactStorage()
        {
            useCompactStorage = true;

View on GitHub (pinned to 88fd0f6a0e)