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

Join us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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