What causes duplicate entry error on duplicate key update?

What causes duplicate entry error on duplicate key update?

This can happen if you update a field that is marked UNIQUE and the second key violation occurs on UPDATE. From your table structure I can see that it’s exactly your case. Remove cnt from your PRIMARY KEY definition. Are you sure that the primary key is correct?

Why is MySQL throwing a duplicate entry error?

Opening “MyTable” and importing with a SQL dump will throw exactly that kind of error if the dump is trying to put entries into “MyOtherTable”, which may already have entries.

Is there a duplicate entry in the table?

It isn’t saying that there is a duplicate entry in the table already, it is saying that there is already one entry in there with that value for the primary key and it is refusing to insert a second for that reason.

What causes a duplicate entry for a primary key in MySQL?

The problem was that in the .sql file the table was chopped into multiple “INSERT INTO” and during the import these queries were executed all together. I had this error from mySQL using DataNucleus and a database created with UTF8 – the error was being caused by this annotation for a primary key:

How to find the primary key in MySQL?

Use SHOW CREATE TABLE your-table-name to see what column is your primary key. Make sure PRIMARY KEY was selected AUTO_INCREMENT. When you execute the insert command you have to skip this key.

How to repair database with autoincrement and primary key?

Repair the database by your domain provider cpanel. The DB I was importing had a conflict during the import due to the presence of a column both autoincrement and primary key. The problem was that in the .sql file the table was chopped into multiple “INSERT INTO” and during the import these queries were executed all together.

Why do I get This error when inserting a record?

ERROR [HY000] [Informix] [Informix ODBC Driver] [Informix]ISAM error: duplicate value for a record with unique key. Error: Could not insert new row – duplicate value in a UNIQUE INDEX column. There must be something with the table schema that I’m missing…

Why do I get duplicate entry on MySQL?

I’m using a memory table. It has several ids and a counter. All data as integers. My code updates the counter by 1 if the data exists or creates a line with counter=1 if not. Occasionally (about 5% of inserts) I get ” Duplicate entry ‘ [key numbers]’ for key 1 What could be the problem?