cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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
Valued Contributor II
Valued Contributor II

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

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.