<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python Notebook recreating lakehouse table after deleting issue in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4771734#M11140</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1269834"&gt;@MangoMagic&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thank you for reaching out to Microsoft Fabric Community.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/10288"&gt;@BhaveshPatel&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/268213"&gt;@Element115&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;for the prompt response.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;May I ask if you have resolved this issue? Please let us know if you have any further issues, we are happy to help.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Jul 2025 06:39:26 GMT</pubDate>
    <dc:creator>v-venuppu</dc:creator>
    <dc:date>2025-07-22T06:39:26Z</dc:date>
    <item>
      <title>Python Notebook recreating lakehouse table after deleting issue</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4760732#M10842</link>
      <description>&lt;P&gt;During development &amp;amp; testing, have to regularly delete lakehouse tables through Explorer side panel and try to recreate it using python code, but it often comes with an error as there are some leftover files in the filesystem for Table folder (probably a log folder).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a better way to create lakehouse tables in Python notebook that doesn't cause an error when trying to recreate table with same name?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MangoMagic_0-1752331898198.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1282638i86BF8711FEA7CC22/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MangoMagic_0-1752331898198.png" alt="MangoMagic_0-1752331898198.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;write_deltalake(
    delta_table_path,
    df,
    mode="overwrite",
    schema_mode="overwrite",
    engine="rust",
    storage_options={"allow_unsafe_rename": "true"}
)&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;---------------------------------------------------------------------------
DeltaError                                Traceback (most recent call last)
Cell In[40], line 12
      7 df = df.apply(lambda col: col if col.name in ["revision","_ETL_Time"]
      8         else col.apply(lambda x: json.dumps(x) 
      9         if not isinstance(x, str) else x))
     10 #df.info()
---&amp;gt; 12 write_deltalake(
     13     delta_table_path,
     14     df,
     15     mode="overwrite",
     16     schema_mode="overwrite",
     17     engine="rust",
     18     storage_options={"allow_unsafe_rename": "true"}
     19 )
     21 display(df)

File ~/jupyter-env/python3.11/lib/python3.11/site-packages/deltalake/writer.py:304, in write_deltalake(table_or_uri, data, schema, partition_by, mode, file_options, max_partitions, max_open_files, max_rows_per_file, min_rows_per_group, max_rows_per_group, name, description, configuration, schema_mode, storage_options, partition_filters, predicate, large_dtypes, engine, writer_properties, custom_metadata)
    301     return
    303 data = RecordBatchReader.from_batches(schema, (batch for batch in data))
--&amp;gt; 304 write_deltalake_rust(
    305     table_uri=table_uri,
    306     data=data,
    307     partition_by=partition_by,
    308     mode=mode,
    309     table=table._table if table is not None else None,
    310     schema_mode=schema_mode,
    311     predicate=predicate,
    312     name=name,
    313     description=description,
    314     configuration=configuration,
    315     storage_options=storage_options,
    316     writer_properties=(
    317         writer_properties._to_dict() if writer_properties else None
    318     ),
    319     custom_metadata=custom_metadata,
    320 )
    321 if table:
    322     table.update_incremental()

DeltaError: Delta transaction failed, version 0 already exists.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jul 2025 14:53:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4760732#M10842</guid>
      <dc:creator>MangoMagic</dc:creator>
      <dc:date>2025-07-12T14:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python Notebook recreating lakehouse table after deleting issue</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4762681#M10905</link>
      <description>&lt;P&gt;in your notebook code include a "remove if exists"&amp;nbsp; step that clears up the remaining artifacts before you attempt to create the new artifact&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jul 2025 19:11:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4762681#M10905</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2025-07-14T19:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Python Notebook recreating lakehouse table after deleting issue</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4767907#M11026</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1269834"&gt;@MangoMagic&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thank you for reaching out to Microsoft Fabric Community.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/100342"&gt;@lbendlin&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;for the prompt response.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I wanted to check if you had the opportunity to review the information provided and resolve the issue..?Please let us know if you need any further assistance.We are happy to help.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2025 07:03:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4767907#M11026</guid>
      <dc:creator>v-venuppu</dc:creator>
      <dc:date>2025-07-18T07:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: Python Notebook recreating lakehouse table after deleting issue</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4768045#M11029</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1269834"&gt;@MangoMagic&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should delete the single table through notebook by right clicking Delta Table and Delete the table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Delete Single Delta Table at a time from Explorer Side Panel. There is no alternative way.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BhaveshPatel_0-1752825762790.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1284260iD96EF66262C708FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BhaveshPatel_0-1752825762790.png" alt="BhaveshPatel_0-1752825762790.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Alternatively, You can drop and recreate the delta table&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DROP TABLE IF EXISTS DimTable&lt;/P&gt;&lt;P&gt;CREATE TABLE IF NOT EXISTS DimTable&lt;BR /&gt;USING DELTA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is managed delta table ( Table with metadata )&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2025 08:14:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4768045#M11029</guid>
      <dc:creator>BhaveshPatel</dc:creator>
      <dc:date>2025-07-18T08:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python Notebook recreating lakehouse table after deleting issue</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4768956#M11060</link>
      <description>&lt;P&gt;Let's first programmatically delete the table(s) properly, and thus let the underlying system perform all the necessary cleanup.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Single table&lt;/P&gt;
&lt;P&gt;PySpark&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;spark.sql("DROP TABLE IF EXISTS schema_name.table_name")
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If multiple tables in a given schema:&lt;/P&gt;
&lt;P&gt;PySpark&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;schema = "your_schema_name"

# List all tables in schema
tables = spark.catalog.listTables(schema)

# Drop each table
for table in tables:
    table_name = table.name
    print(f"Dropping table {schema}.{table_name}")
    spark.sql(f"DROP TABLE IF EXISTS {schema}.{table_name}")
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Combining these, let's look at a full PySpark solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;schema = "your_schema_name"

# Step 1: List all tables in the schema
tables = spark.catalog.listTables(schema)

# Step 2: Drop all tables
for t in tables:
    print(f"Dropping table {schema}.{t.name}")
    spark.sql(f"DROP TABLE IF EXISTS {schema}.{t.name}")

# Step 3: Recreate all tables with a sample schema
# WARNING: Replace sample_schema with actual schemas if you want original structures back

sample_schema = "id INT, name STRING"

for t in tables:
    table_full_name = f"{schema}.{t.name}"
    print(f"Recreating table {table_full_name}")
    spark.sql(f"""
        CREATE TABLE {table_full_name} ({sample_schema})
        USING DELTA
        LOCATION '/mnt/datalake/{schema}/{t.name}'
    """)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you still get complaints about the table names, this means the lakehouse server hasn't update its state yet.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hence, what I would do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;0_create pipeline&lt;/P&gt;
&lt;P&gt;1_create a Notebook activity to run the delete Pyspark code above&lt;/P&gt;
&lt;P&gt;2_use the Web activity with the new lakehouse REST API to force the lakehouse to sync (instead of a Wait activity because we can't know how long it's gonna take)&lt;/P&gt;
&lt;P&gt;3_on success, next activity is a Notebook recreating the tables (somehow, you would need to save the table names somewhere, maybe another lakehouse dedicated only to store metadata)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had the same issue with lakehouse tables on which write I/O wasn't finished by the time the next activity is ready to run. that was before the new REST API, so at the time I used a PySpark script to force the lakehouse to refresh and sync all metadata. and it worked.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Haven't used the Web activity, so just a suggestion, and to be tested.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Aug 2025 15:48:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4768956#M11060</guid>
      <dc:creator>Element115</dc:creator>
      <dc:date>2025-08-06T15:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python Notebook recreating lakehouse table after deleting issue</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4771734#M11140</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1269834"&gt;@MangoMagic&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thank you for reaching out to Microsoft Fabric Community.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/10288"&gt;@BhaveshPatel&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/268213"&gt;@Element115&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;for the prompt response.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;May I ask if you have resolved this issue? Please let us know if you have any further issues, we are happy to help.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2025 06:39:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4771734#M11140</guid>
      <dc:creator>v-venuppu</dc:creator>
      <dc:date>2025-07-22T06:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python Notebook recreating lakehouse table after deleting issue</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4776024#M11242</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1269834"&gt;@MangoMagic&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I hope the information provided is helpful.I wanted to check whether you were able to resolve the issue with the provided solutions.Please let us know if you need any further assistance.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jul 2025 06:45:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Python-Notebook-recreating-lakehouse-table-after-deleting-issue/m-p/4776024#M11242</guid>
      <dc:creator>v-venuppu</dc:creator>
      <dc:date>2025-07-25T06:45:08Z</dc:date>
    </item>
  </channel>
</rss>

