Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
QuinnDatatyk
Frequent Visitor

Spark Write to OneLake cannot overwrite data schema

I cannot overwrite table schema using spark.write.mode("overwrite")

For example, create a table with 2 column: col1 as int and col2 as string

QuinnDatatyk_0-1713088635792.png

Then change col1 to data type int and use spark.write.mode("overwrite")

QuinnDatatyk_2-1713088720743.png

It return error 

QuinnDatatyk_3-1713088773822.png

 

 

 

1 ACCEPTED SOLUTION
frithjof_v
Super User
Super User

I think if you want to overwrite the schema while overwriting the data, you could write like this:

 

df\
   .write\
   .mode("overwrite")\
   .option("overwriteSchema", "true")\
   .saveAsTable("tableName")

 

So I think you only need to add .option("overwriteSchema", "true") in your code

 

 

Ref. https://community.fabric.microsoft.com/t5/General-Discussion/Dropping-and-recreating-lakehouse-table...

 

View solution in original post

2 REPLIES 2
frithjof_v
Super User
Super User

I think if you want to overwrite the schema while overwriting the data, you could write like this:

 

df\
   .write\
   .mode("overwrite")\
   .option("overwriteSchema", "true")\
   .saveAsTable("tableName")

 

So I think you only need to add .option("overwriteSchema", "true") in your code

 

 

Ref. https://community.fabric.microsoft.com/t5/General-Discussion/Dropping-and-recreating-lakehouse-table...

 

I tried and successed. Thank you very much.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.