Welcome to Discussion Forum, where you can ask questions and receive answers from other members of the community.

How can I reset the product ID in prestashop??

0 like 0 dislike
Hello, I have been searching for a while but haven't found the answer
Is there any way to reset the product ID? I have insert and deleted many products and I just realized that the deleted product's id is not being re-occupied, for example I have #1 to #14 ID then I delete #10 and #11, when I add new product it becomes #15, not taking the #10 spot
Is there any way to re generate the IDs so the vacant IDs can be used? because at this rate the ID will be only piled up
asked Mar 1, 2017 in Prestashop by harsh (8,710 points)

1 Answer

1 like 0 dislike

I don't think that it is a good idea to reset the auto increment primary key indexes in your table as it can cause many problems.

The database doesn't really care about sequential values. Is there any specific reason for doing that? Think again and ask "why do you need to reset product ids?"

Primary autoincrement keys in database are used to uniquely identify a given row and shouldn't be given any business meaning. So leave the primary key as is. If you really need the sequencial data in every row then you can add another column called for example product_count. Then when you delete a record from the database you may want to send an additional UPDATE statement in order to decrement the product_count column of all rows that have product_count greater than the one you are currently deleting.

But if you still want to make new product add at the place from where an ID is deleted then you might want to run following SQL command through terminal or phpMyAdmin.

Before doing this don't forget to take the backup of your database.

SET @num := 0;
UPDATE name_of_your_table SET id = @num := (@num+1);
ALTER TABLE name_of_your_table AUTO_INCREMENT = 1;
Product table can save upto 9999999999 product ids. Do you really think that not resetting the product IDs is a problem?
answered Mar 2, 2017 by Mayank Singh (940 points)

Related questions

0 like 0 dislike
1 answer 51 views
0 like 0 dislike
0 answers 389 views
0 like 0 dislike
0 answers 18 views
18 views asked Apr 27, 2017 in Prestashop by harsh (8,710 points)
0 like 0 dislike
2 answers 773 views
0 like 0 dislike
0 answers 188 views