Duplicate entry '35839' for key 'PRIMARY'
I am receiving the above error message suddenly on a database I keep logs in. This is an auto-increment field which the last key for the last entry is 35838
. If I perform a search for the key 35839
, no results are returned. (Also, I'm looking at the database through phpMyAdmin and can see that the last record is 35838
.)
The table structure is:
CREATE TABLE IF NOT EXISTS `raw_data` (
`id` int(12) unsigned NOT NULL AUTO_INCREMENT,
`oid` int(12) unsigned NOT NULL,
`data` longtext NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `oid` (`oid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=35839 ;
You can see that the next ID it is expecting to make is 35839
. Yet it thinks that it is already in the table…
Also, the oid
that is trying to be inserted is also unique. It is an order ID being generated by another system and is never duplicated. Plus, I've checked to see if it is already in the database and it is also not in the database already.
Is there anything I could be overlooking as to why this would suddenly start telling me that it is trying to enter a duplicate? It has been working for two years now. haha~
Thanks!
Select Statement
Select * From raw_data Where id = 35839;
MySQL returned an empty result set (i.e. zero rows). (Query took 0.0012 sec)
Best Answer
From @ypercubeᵀᴹ's suggestion:
I then ran
Check Table raw_data Extended
which resulted in:I then ran
Repair Table raw_data Extended
which resulted in:This fixed the problem.