apache/seatunnel · warning

Column '{}' in table {} is NOT NULL but has no DEFAULT; addi

Error message

Column '{}' in table {} is NOT NULL but has no DEFAULT; adding as NULL to allow addition to a non-empty table.

What it means

When applying an ALTER TABLE ADD COLUMN schema change on SQL Server, the incoming column is NOT NULL but has no DEFAULT value. SQL Server forbids adding such a column to a non-empty table, so SeaTunnel downgrades the column to NULLable and logs this warning instead of failing. Existing rows get NULL until CDC UPDATE events populate values.

Source

Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlServerDialect.java:322

                        .append(" ");

        if (column.getDefaultValue() != null) {
            // Handle default values
            String defaultValueClause = sqlClauseWithDefaultValue(typeDefine, sourceDialectName);
            sqlBuilder.append(defaultValueClause);
        }

        if (!column.isNullable()) {
            if (column.getDefaultValue() != null) {
                // A DEFAULT is present — SQL Server can populate existing rows, so NOT NULL is
                // safe.
                sqlBuilder.append(" NOT NULL");
            } else {
                // SQL Server forbids adding a NOT NULL column without a DEFAULT to a non-empty
                // table.
                // Add as NULL so that existing rows are not affected; subsequent CDC UPDATE events
                // will fill in the actual values for those rows.
                log.warn(
                        "Column '{}' in table {} is NOT NULL but has no DEFAULT; adding as NULL "
                                + "to allow addition to a non-empty table.",
                        column.getName(),
                        tablePath.getFullName());
                sqlBuilder.append(" NULL");
            }
        }

        ddlSQL.add(sqlBuilder.toString());
        // Process column comment
        if (column.getComment() != null) {
            ddlSQL.add(buildColumnCommentSQL(tablePath, column));
        }

        // Execute the DDL statement
        executeDDL(connection, ddlSQL);
    }

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Add a DEFAULT value to the column definition at the source before the schema change propagates.
  2. Pre-add the column manually on SQL Server with NOT NULL + DEFAULT so SeaTunnel skips the auto-add.
  3. Accept the warning and rely on subsequent CDC UPDATE events to backfill values; then tighten the constraint manually.
  4. Backfill existing rows with UPDATE after the DDL and alter the column back to NOT NULL.

Example fix

-- source DDL before (causes downgrade)
ALTER TABLE users ADD status VARCHAR(20) NOT NULL;
-- after
ALTER TABLE users ADD status VARCHAR(20) NOT NULL DEFAULT 'active';
Defensive patterns

Strategy: validation

Validate before calling

// before emitting AlterTableAddColumnEvent for SQL Server target
if (!column.isNullable() && column.getDefaultValue() == null) {
    log.warn("Column {} will be added as NULL on SQL Server; set a DEFAULT",
        column.getName());
}

Type guard

boolean isSqlServerSafeAddition(Column c) {
    return c.isNullable() || c.getDefaultValue() != null;
}

Prevention

When it happens

Trigger: applySchemaChange() receives an AlterTableAddColumnEvent where column.isNullable() is false and column.getDefaultValue() is null, and the target SQL Server table may contain rows.

Common situations: CDC schema-evolution pipelines where the source database adds a NOT NULL column without a default (allowed there because rows are backfilled later, or the source engine permits it); syncing MySQL/Postgres DDL to SQL Server.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/163b5ea75dc4bd4a. Report an issue: GitHub.