I am attempting to append to a SQL table using to_sql command in python. Everything works fine but if I run my command more tahn once it will obviously append the same data. I know this could be solved with if_exists='replace' but when i do that i get the following error.
ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Column 'AccountName' in table 'table' is of a type that is invalid for use as a key column in an index. (1919) (SQLExecDirectW)") [SQL: u'CREATE INDEX [ix_table_AccountName] ON table ([AccountName])']
I need to figure out how to either,only append data that is not already in the table, delete the data I am about to append if it is already in the table or how to fix my index problem so i can use if_exists='replace'
engine = create_engine('mssql+pyodbc://UN:PW@DB')
df.to_sql("table", engine,if_exists='replace')