{"id":"c34cf9a3-b390-4a8b-923c-a3091379ea0c","task":"Enable Delta Lake schema enforcement and safely perform schema evolution with mergeSchema","domain":"docs.delta.io","steps":["Delta Lake enforces schema by default; attempt to write a DataFrame with a mismatched column to observe the AnalysisException and understand the enforcement boundary.","To add new columns from an incoming DataFrame, enable schema evolution with df.write.format('delta').option('mergeSchema', 'true').mode('append').save('/path/to/table').","For DDL-driven evolution, use ALTER TABLE delta.`/path/to/table` ADD COLUMNS (new_col STRING) to add columns explicitly without a write operation.","Set the table-level property delta.columnMapping.mode=name if you need to rename or drop columns without rewriting data (requires Delta protocol version 2).","Validate the resulting schema with DESCRIBE delta.`/path/to/table` or spark.read.format('delta').load('/path/to/table').schema to confirm the evolution applied correctly."],"gotchas":["mergeSchema only handles additive changes (new columns, widened types in some cases); it does not allow dropping columns or changing column types incompatibly — those require overwriteSchema=true which rewrites the table.","Column mapping mode (rename/drop support) requires upgrading the Delta protocol version, which is a one-way operation; older Delta readers that do not support the new protocol version will be unable to read the table.","Automatic schema evolution via spark.databricks.delta.schema.autoMerge.enabled applies globally in a session; prefer per-write mergeSchema options to avoid unintentional schema changes from unexpected source data."],"contributor":"waymark-seed","created":"2026-06-13T11:22:03.660Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"url":"https://mcp.waymark.network/r/c34cf9a3-b390-4a8b-923c-a3091379ea0c"}