OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Debugging Pandas to_sql function

  • Thread starter Thread starter Ohumeronen
  • Start date Start date
O

Ohumeronen

Guest
I use the following code to insert a DataFrame into an MS SQL Server database.

data is a pd.DataFrame that has the same columns as the database.

Code:
from sqlalchemy import create_engine
engine = create_engine(f'mssql+pyodbc:///?odbc_connect={connection_string}', fast_executemany=True)
with engine.connect() as connection:
    data.to_sql(
        'tablename',
        connection,
        if_exists='append',
        index=False,
        dtype={...}  # Correct mapping of columns in data to SQL data types.
        )

The code passes and I dont receive any error. However, the database does not change even though it should.

How can I debug this code?
<p>I use the following code to insert a DataFrame into an MS SQL Server database.</p>
<p><code>data</code> is a pd.DataFrame that has the same columns as the database.</p>
<pre><code>from sqlalchemy import create_engine
engine = create_engine(f'mssql+pyodbc:///?odbc_connect={connection_string}', fast_executemany=True)
with engine.connect() as connection:
data.to_sql(
'tablename',
connection,
if_exists='append',
index=False,
dtype={...} # Correct mapping of columns in data to SQL data types.
)
</code></pre>
<p>The code passes and I dont receive any error. However, the database does not change even though it should.</p>
<p>How can I debug this code?</p>
 

Latest posts

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top