我正在使用pandas读写MySQL表格,我相信我在写入时尝试设置为索引的值是唯一的。我在没有索引的情况下检查了表格,并且count(distinct(id))
与count(id)
给出了相同的行数。然而,我仍然遇到了错误。
'ValueError: duplicate name in index/columns: cannot insert product_id, already exists'
如果我设置index=True, index_label="id"
我已经尝试了reset_index
,但它没有帮助。
df.to_sql(name=config.DB_TABLE, con=connection, schema=config.DB_SCHEMA, if_exists='fail', index=True, index_label="id")
我做错了什么?
to_sql
函数的代码吗? - TYZ