This question has been flagged
1 Reply
9621 Views

when i try and save a new product i get an Integrity Error : duplicate key value violates unique constraint "product_template_pkey"

this is after importing some products to the DB via SQL to tables poduct_template and product_product.

i dont have any repeated primary key id values in the first column of either table.

where should i be looking for the fault ?

Avatar
Discard
Author

Google: 'Sequence-Manipulation Functions'... Using pgAdmin you can view SEQUENCE information via a dialogue box and update the sequence value to equal the next desired record ID.

Author Best Answer
// Login to psql and run the following
// What is the result?
SELECT MAX(id) FROM your_table;

// Then run...
// This should be higher than the last result.
SELECT nextval('your_table_id_seq');

// If it's not higher... run this set the sequence last to your highest pid it. 
// (wise to run a quick pg_dump first...)
SELECT setval('your_table_id_seq', (SELECT MAX(id) FROM your_table));
Avatar
Discard