MySQL Forums
Forum List  »  Connector/Python

Duplicate PRIMARY key problem
Posted by: harry sheng
Date: October 20, 2016 01:59PM

environment:
mysql 5.7 on rhl6
mysql-python/connector
python 2.7.12 on windows, python 2.6.6 on rhl6

I have a time-series fact table with primary key on ID and a timestamp column. The ID column is a mysql auto-gen column and is unique for every new record inserted into this table. (why the timestamp column is in the primary key is not import here).

I'm writing a python script to popuate the table with records for a list of objects at every 15-minute mark.

The table was initially empty. I started populating the table from 00-minute mark, and records were committed to the table without problem. But it failed on the first 15-minute mark record with a duplicate PRIMARY key error.

I truncated the table and started the script again, it failed at the same place with the same error.

I truncated the table and change the script to start from 15-minute mark, the script successfully created and committed all the 15-minute mark records, then failed at the first 30-minute mark record with the same duplicate PRIMARY key error.

I then get the "create table" statement from workbench, drop and recreate the table, rerun the script, everything works fine. The problem disappeared!

Now I'm scratching my head to try to understand this. Could somebody help me please?

Options: ReplyQuote


Subject
Written By
Posted
Duplicate PRIMARY key problem
October 20, 2016 01:59PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.