Hey,

i deleted all orders & customers to setup a copy of an existing shop. It results in random mysql errors when adding a product to the basket:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'commerce_line_item-36-0-0-und' for key 'PRIMARY': INSERT INTO {field_data_commerce_unit_price} (entity_type, entity_id, revision_id, bundle, delta, language, commerce_unit_price_amount, commerce_unit_price_currency_code, commerce_unit_price_data) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => commerce_line_item [:db_insert_placeholder_1] => 36 [:db_insert_placeholder_2] => 36 [:db_insert_placeholder_3] => product [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 8995 [:db_insert_placeholder_7] => EUR [:db_insert_placeholder_8] => a:2:{s:10:"components";a:2:{i:0;a:3:{s:4:"name";s:10:"base_price";s:5:"price";a:3:{s:6:"amount";d:7559;s:13:"currency_code";s:3:"EUR";s:4:"data";a:0:{}}s:8:"included";b:1;}i:1;a:3:{s:4:"name";s:12:"tax|btw_hoog";s:5:"price";a:3:{s:6:"amount";d:1436;s:13:"currency_code";s:3:"EUR";s:4:"data";a:1:{s:8:"tax_rate";a:11:{s:4:"name";s:8:"btw_hoog";s:13:"display_title";s:10:"BTW (19%) ";s:11:"description";s:0:"";s:4:"rate";s:3:".19";s:4:"type";s:3:"vat";s:15:"rules_component";s:1:"1";s:15:"price_component";s:12:"tax|btw_hoog";s:20:"calculation_callback";s:27:"commerce_tax_rate_calculate";s:6:"module";s:15:"commerce_tax_ui";s:5:"title";s:8:"btw hoog";s:10:"admin_list";b:1;}}}s:8:"included";b:1;}}s:11:"include_tax";s:8:"btw_hoog";} ) in field_sql_storage_field_storage_write() (regel 424 van /home/users/loopsftp/loopfietsstore.com/modules/field/modules/field_sql_storage/field_sql_storage.module).

When looking at field_data_commerce_unit_price the primary key is already at 149. I didn't truncated any tables. Just deleted stuff from the backend. The error is more or less random sometimes adding a new product works fine...

gr Volkan

Comments

rszrama’s picture

Category: bug » support
Priority: Major » Normal
Status: Active » Closed (works as designed)

You cannot just delete entities in Drupal 7. There's almost always going to be field data attached that you also need to clean up, not to mention revision data. You can do this through the UI on each item individually or use Views Bulk Operations to setup a View to do it all at once. The quick fix for you now would be to update your customer and order tables' autoincrement key to 1 higher than whatever you had before. The longer fix will be for you to empty out all the related field tables and clear your caches.

muschpusch’s picture

Which tables do you mean? I actually deleted everything from the UI but some of the products created by commerce_migrate couldn't be deleted so i deleted them in the database.

Would this be enough:
commerce_order
commerce_order_revision
field_data_commerce_order_total
field_revision_commerce_order_total
commerce_customer_profile
field_data_commerce_customer_address

The table 'field_data_commerce_unit_price' too?

Thanks for the quick reply!

rszrama’s picture

Any table with commerce in it would need to be truncated, whether it's for a Commerce entity or field. Don't forget the various revision tables, too.

muschpusch’s picture

Hey... ehm... truncating isn't an option anymore :)

The quick fix for you now would be to update your customer and order tables' autoincrement key to 1 higher than whatever you had before.
The longer fix will be for you to empty out all the related field tables and clear your caches.

Which tables for the quick fix? Or which are the related field tables for option two????

rszrama’s picture

I'm sorry, I don't have a list. There are other threads that do. If you need more help on this, try asking in #drupal-commerce on IRC.

muschpusch’s picture

Solution: truncate field_data_commerce_unit_price you will get an error on the next table. Truncate that one, next error and so... In the end all orders will be deleted but the products are still there..

chriscalip’s picture

Since this ranks high on google; I figured I'd help our fellow drupal commerce users with a good enough answer.

truncate commerce_order;
truncate commerce_order_revision;
truncate field_data_commerce_line_items;
truncate field_revision_commerce_line_items;
truncate field_data_commerce_order_total;
truncate field_revision_commerce_order_total;
truncate field_data_commerce_customer_billing;
truncate field_revision_commerce_customer_billing;
truncate commerce_line_item;
truncate field_data_commerce_product;
truncate field_data_commerce_unit_price;
truncate field_data_commerce_total;
truncate field_data_commerce_display_path;
truncate field_revision_commerce_product;
truncate field_revision_commerce_unit_price;
truncate field_revision_commerce_total;
truncate field_revision_commerce_display_path;
truncate field_data_commerce_customer_shipping;
truncate field_revision_commerce_customer_shipping;

giorgosk’s picture

my 2 cents

####	Delete all orders 

	truncate commerce_line_item;
	truncate commerce_order;
	truncate commerce_order_revision;

	truncate field_data_commerce_customer_address;
	truncate field_data_commerce_customer_billing;
	truncate field_data_commerce_customer_shipping;
	truncate field_data_commerce_display_path;
	truncate field_data_commerce_line_items;
	truncate field_data_commerce_order_total;
	truncate field_data_commerce_product;
	truncate field_data_commerce_total;
	truncate field_data_commerce_unit_price;

	truncate field_revision_commerce_customer_billing;
	truncate field_revision_commerce_customer_shipping;
	truncate field_revision_commerce_display_path;
	truncate field_revision_commerce_line_items;
	truncate field_revision_commerce_order_total;
	truncate field_revision_commerce_product;
	truncate field_revision_commerce_total;
	truncate field_revision_commerce_unit_price;
amfis’s picture

There is more cents to this :) (for my site setup)

truncate commerce_customer_profile;
truncate commerce_customer_profile_revision;
truncate field_data_commerce_shipping_service;
truncate field_revision_commerce_shipping_service;

truncate commerce_line_item;
truncate commerce_order;
truncate commerce_order_revision;

truncate field_data_commerce_customer_address;
truncate field_data_commerce_customer_billing;
truncate field_data_commerce_customer_shipping;
truncate field_data_commerce_display_path;
truncate field_data_commerce_line_items;
truncate field_data_commerce_order_total;
truncate field_data_commerce_product;
truncate field_data_commerce_total;
truncate field_data_commerce_unit_price;

truncate field_revision_commerce_customer_address;
truncate field_revision_commerce_customer_billing;
truncate field_revision_commerce_customer_shipping;
truncate field_revision_commerce_display_path;
truncate field_revision_commerce_line_items;
truncate field_revision_commerce_order_total;
truncate field_revision_commerce_product;
truncate field_revision_commerce_total;
truncate field_revision_commerce_unit_price;
vegtabill’s picture

Just wanted to say thank you, as this was a life-saver. I knew better than to manually mess with the Order tables... what was I thinking?

Thanks again!

reubenlara’s picture

Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you . Just wasted three days on this. All fixed.

MohammadMoussa-Lebanon’s picture

Thank you this is the best solution.

cprofessionals’s picture

Latest Drupal 7.54 and Drupal commerce 7.x.-1.13 this still fixed my issue. Thank you!