{"record":{"id":"163b5ea75dc4bd4a","repo":"apache/seatunnel","slug":"column-in-table-is-not-null-but-has-no-def","errorCode":null,"errorMessage":"Column '{}' in table {} is NOT NULL but has no DEFAULT; adding as NULL to allow addition to a non-empty table.","messagePattern":"Column '(.+?)' in table (.+?) is NOT NULL but has no DEFAULT; adding as NULL to allow addition to a non-empty table\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlServerDialect.java","lineNumber":322,"sourceCode":"                        .append(\" \");\n\n        if (column.getDefaultValue() != null) {\n            // Handle default values\n            String defaultValueClause = sqlClauseWithDefaultValue(typeDefine, sourceDialectName);\n            sqlBuilder.append(defaultValueClause);\n        }\n\n        if (!column.isNullable()) {\n            if (column.getDefaultValue() != null) {\n                // A DEFAULT is present — SQL Server can populate existing rows, so NOT NULL is\n                // safe.\n                sqlBuilder.append(\" NOT NULL\");\n            } else {\n                // SQL Server forbids adding a NOT NULL column without a DEFAULT to a non-empty\n                // table.\n                // Add as NULL so that existing rows are not affected; subsequent CDC UPDATE events\n                // will fill in the actual values for those rows.\n                log.warn(\n                        \"Column '{}' in table {} is NOT NULL but has no DEFAULT; adding as NULL \"\n                                + \"to allow addition to a non-empty table.\",\n                        column.getName(),\n                        tablePath.getFullName());\n                sqlBuilder.append(\" NULL\");\n            }\n        }\n\n        ddlSQL.add(sqlBuilder.toString());\n        // Process column comment\n        if (column.getComment() != null) {\n            ddlSQL.add(buildColumnCommentSQL(tablePath, column));\n        }\n\n        // Execute the DDL statement\n        executeDDL(connection, ddlSQL);\n    }\n","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlServerDialect.java#L304-L340","documentation":"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.","triggerScenarios":"applySchemaChange() receives an AlterTableAddColumnEvent where column.isNullable() is false and column.getDefaultValue() is null, and the target SQL Server table may contain rows.","commonSituations":"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.","solutions":["Add a DEFAULT value to the column definition at the source before the schema change propagates.","Pre-add the column manually on SQL Server with NOT NULL + DEFAULT so SeaTunnel skips the auto-add.","Accept the warning and rely on subsequent CDC UPDATE events to backfill values; then tighten the constraint manually.","Backfill existing rows with UPDATE after the DDL and alter the column back to NOT NULL."],"exampleFix":"-- source DDL before (causes downgrade)\nALTER TABLE users ADD status VARCHAR(20) NOT NULL;\n-- after\nALTER TABLE users ADD status VARCHAR(20) NOT NULL DEFAULT 'active';","handlingStrategy":"validation","validationCode":"// before emitting AlterTableAddColumnEvent for SQL Server target\nif (!column.isNullable() && column.getDefaultValue() == null) {\n    log.warn(\"Column {} will be added as NULL on SQL Server; set a DEFAULT\",\n        column.getName());\n}","typeGuard":"boolean isSqlServerSafeAddition(Column c) {\n    return c.isNullable() || c.getDefaultValue() != null;\n}","tryCatchPattern":null,"preventionTips":["Always define DEFAULT values for NOT NULL columns in evolving schemas","Pre-add such columns on SQL Server manually with the constraint intact","Plan a post-DDL backfill + ALTER to NOT NULL when relying on CDC updates"],"tags":["jdbc","sqlserver","schema-evolution","ddl","not-null"],"backgroundTag":"invalid-state-transition","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}