cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

pyspark delta table schema evolution

zyang
Contributor

I am using the schema evolution in the delta table and the code is written in databricks notebook.

 df.write
        .format("delta")
        .mode("append")
        .option("mergeSchema", "true")
        .partitionBy("date")
        .save(path)

But I still got the error below. Is it correct to define the schema and enable the mergeSchema at the same time?

AnalysisException: The specified schema does not match the existing schema at path.
== Specified ==
 
    root
    -- A: string (nullable = false)
    -- B: string (nullable = true)
    -- C: long (nullable = true)
    
== Existing ==
    root
    -- A: string (nullable = true)
    -- B: string (nullable = true)
    -- C: long (nullable = true)
 
== Differences==
- Field A is non-nullable in specified schema but nullable in existing schema.
 
If your intention is to keep the existing schema, you can omit the
schema from the create table command. Otherwise please ensure that
the schema matches.

1 REPLY 1

Noopur_Nigam
Databricks Employee
Databricks Employee

Hi @z yang​ Please provide the df creation code as well to understand the complete exception and scenario.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group