I am trying to use Pandas to_sql method to input a dataframe into a SQL Server database, and I am getting the error:
'23000', "[23000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Violation of UNIQUE KEY constraint ... Cannot insert duplicate key in object
Someone else posted a similar problem here: Pandas to_sql 'append' to an existing table causes Python crash
However, his solution was basically that he needed to drop duplicates for the primary key because he was submitting the primary key more than once. I am not even trying to submit the primary key, I want SQL Server to assign that. Here is the method I call:
df.to_sql('table_name', engine, if_exists='append', index=False, chunksize=1000)
I know the engine works to connect to the database because if I use the read_sql method it works fine returning the data from what's in the database. I'm just not able to write to the database, it apparently sees me re-using primary keys when I'm not even trying to touch the primary keys. Can anyone help?