Pandas to_sql fails on duplicate primary key

后端 未结 6 1046
执笔经年
执笔经年 2020-12-28 18:13

I\'d like to append to an existing table, using pandas df.to_sql() function.

I set if_exists=\'append\', but my table has primary keys.

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-28 18:29

    please note that the "if_exists='append'" related to the existing of the table and what to do in case the table not exists. The if_exists don't related to the content of the table. see the doc here: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html

    if_exists : {‘fail’, ‘replace’, ‘append’}, default ‘fail’ fail: If table exists, do nothing. replace: If table exists, drop it, recreate it, and insert data. append: If table exists, insert data. Create if does not exist.

提交回复
热议问题