Question

I am using cfwheels (coldfusion orm framework).

I recently moved some data from my previous host to a new one. Now I am trying to insert into a table, but am getting an error message: "Error Executing Database Query. Duplicate entry '13651' for key 'PRIMARY'"

I looked into the database and it appears a record with id 13651 already exists. So I think the problem is with mysql generating the right auto increment value.

Was it helpful?

Solution

It seems Auto_Increment value is damaged or not set to max value in that column. It's possible due to bulk insert.

So as per solution, set the maximum PK value + 1 as new AUTO_INCREMENT value. Now when you insert the records in this table, they will automatically pick the next incremented correctly.

ALTER.TABLE tablename AUTO_INCREMENT = value

OTHER TIPS

Is the rest of the data for that record, and the one you are trying to insert, the same? If you you might just need to tell the ORM to replace that value?

If primary key has auto increment attribute turned on, do not insert it manually. remove that primary key part from your insert query (whatever the syntax according to the taste of your ORM framework).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top