I'm trying to insert a row into my database like I always made.
The query I'm using is the following :
INSERT INTO catbeni (Nome) VALUES ('Televisore')
As you can see, I'm using the simplest way to insert a row into the database. Now, I display my table with an HTML table, and I allow people to remove rows directly from the HTML page. By clicking a button, they execute the following query to remove the row :
DELETE FROM table WHERE id=any_id
The problem is that when I delete each records, so that I've got no record in my table, I get this error trying to insert a new one into my database :
Failed to read auto-increment value from storage engine
I already inserted rows in an empty table, but I've never had this error. Looking for a solution online I found a few questions on Stack Overflow, but none of the solutions worked for me. The solution I found most of the time is executing a query on my table to reset the AUTO_INCREMENT
property of my PRIMARY KEY
.
This is the query, caught from this question :
ALTER TABLE `table_name` AUTO_INCREMENT = 1
The only solution that worked for me, is accessing phpMyAdmin and inserting manually a row with any id, but I naturally can't solve my problem following this way.
This is the CREATE TABLE
statement used to create my table :
CREATE TABLE `catbeni` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Nome` varchar(255) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT
I hope I'm clear!