After updating to the latest drupal core I'm getting the issue as per below error display, when adding a product in the cart as anonymous user or as admin (the only registered user at the moment).
I've noticed a similar issue with commerce_order was reported some time ago: http://drupal.org/node/1204210
But there is no solution to the issue outside tweaking with the database.
I'll try to do that, but I was wondering if anybody else experienced the same issue upgrading commerce to latest drupal core.
Needless to say that this issue is now blocking the webshop as no normal user can post an order.
Luckily we are in beta, but I need to fix this ASAP.
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'commerce_order-9-0-0-und' for key 1: INSERT INTO {field_data_commerce_order_total} (entity_type, entity_id, revision_id, bundle, delta, language, commerce_order_total_amount, commerce_order_total_currency_code, commerce_order_total_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_order [:db_insert_placeholder_1] => 9 [:db_insert_placeholder_2] => 74 [:db_insert_placeholder_3] => commerce_order [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 0 [:db_insert_placeholder_7] => GBP [:db_insert_placeholder_8] => a:1:{s:10:"components";a:1:{i:0;a:3:{s:4:"name";s:10:"base_price";s:5:"price";a:3:{s:6:"amount";i:0;s:13:"currency_code";s:3:"GBP";s:4:"data";a:0:{}}s:8:"included";b:1;}}} ) in field_sql_storage_field_storage_write() (line 448 of /home/shop/modules/field/modules/field_sql_storage/field_sql_storage.module).
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | ghost-products.jpg | 35.44 KB | Egan7 |
Comments
Comment #1
FrancescoUK commentedSomething more to add....
If I go to Store Administration, I'm not able to create Customer Profiles or Orders manually either.
I get a similar exception in other modules.
Comment #2
FrancescoUK commentedOK, I've sorted the issue following the indication of the link I provided.
I truncated all the commerce_order & customer and field_data/revision and I could restart.
I really don't know what happened, but somehow the database went wrong.
Never mind, as it's a beta I just had few test products and truncating and creating some new ones did the trick.
Having said that, a proper "Reset" button or "Repair" feature might do for worst case scenarios like mine.
Comment #3
rszrama commentedLooking at the bug, it's apparently trying to calculate and insert an order total for an order that already exists. I have no clue why it would be trying an insert instead of an update, but if you're creating this order as a new user, then such an order must already have existed at some point in time. All I can figure is that you manually deleted order data but did not delete the coordinating field data at the same time, so Drupal now expects order 9 to not have any field data yet and is trying to insert the new price field value.
Can you confirm this reading of things?
Because I'm not sure this really is a Drupal Commerce issue, I'm demoting it to major; definitely a problem, but if it's caused by manual database administration, well... that way is fraught with peril.
Comment #4
amateescu commentedGlad you figured this out :)
Comment #5
rszrama commentedAhh, heh, I should've refreshed. ; )
There really is no way to anticipate this and provide a form for correcting it... you just shouldn't delete any entity data directly in the database. If you need to remove entities in bulk all at once, I recommend using Views Bulk Operations so the proper API requests get fired to clean up all the data and clear caches properly.
Comment #6
rszrama commentedComment #7
FrancescoUK commentedThis is a bug, now I could re-reproduce it:
1. Just add something to the cart as anonymous user.
2. Then view the cart and remove the items you have in the cart such you have nothing left.
3. Go back to the products and try to add one again, you get the error.
Please give a try. It's with Drupal 7.12 and Commerce 7.x-1.2.
I now get the following:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'commerce_line_item-4-0-0-und' for key 1: 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] => 4 [:db_insert_placeholder_2] => 4 [:db_insert_placeholder_3] => product [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 5000 [:db_insert_placeholder_7] => GBP [:db_insert_placeholder_8] => a:1:{s:10:"components";a:1:{i:0;a:3:{s:4:"name";s:10:"base_price";s:5:"price";a:3:{s:6:"amount";s:4:"5000";s:13:"currency_code";s:3:"GBP";s:4:"data";a:1:{s:10:"components";a:0:{}}}s:8:"included";b:1;}}} ) in field_sql_storage_field_storage_write() (line 448 of /home/shop/modules/field/modules/field_sql_storage/field_sql_storage.module).
Comment #8
FrancescoUK commentedI assume that if I do the same as admin I would get the same issue, but I don't want to give try.
Comment #9
FrancescoUK commentedI reset with truncate the database and re-created two test products.
Tried the sequence I previously mentioned but I cannot reproduce.
There must be some sort of sequence that I'm repeating that creates the problem, but until I don't find it and can reproduce the issue again and again I close this one.
Comment #10
CanOne commentedI had this error message
EDIT: it was showing up when i tried to put something in my cart but only as anonymous user.
I installed everything like 4 times new and configured everything manually, i tried kickstart once.
Now i installed everything again but without using a database prefix, and everything is working fine for the moment.
fyi the newest working installation is not exactly the same as the others. i havent installed all modules, but the most important things are working for me.
So I´m not 100% sure if it belongs to the db prefix or some missing modules.
Comment #11
5n00py commentedPDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'commerce_line_item-6-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] => 6 [:db_insert_placeholder_2] => 6 [:db_insert_placeholder_3] => product [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 30 [:db_insert_placeholder_7] => UAH [:db_insert_placeholder_8] => a:1:{s:10:"components";a:2:{i:0;a:3:{s:4:"name";s:10:"base_price";s:5:"price";a:3:{s:6:"amount";s:2:"60";s:13:"currency_code";s:3:"UAH";s:4:"data";a:1:{s:10:"components";a:0:{}}}s:8:"included";b:1;}i:1;a:3:{s:4:"name";s:10:"base_price";s:5:"price";a:3:{s:6:"amount";i:-30;s:13:"currency_code";s:3:"UAH";s:4:"data";a:0:{}}s:8:"included";b:1;}}} ) в функции field_sql_storage_field_storage_write() (строка 448 в файле /home/snoopy/www/domain/dev7.bijugrad.com.ua/htdocs/modules/field/modules/field_sql_storage/field_sql_storage.module).I have same problem. But some products works good. So this is product-related issue. im using feeds to import products.
Comment #12
5n00py commentedFixed by truncate all problem tables. For me this errors caused by inaccurate working with db from phpMyAdmin.
Comment #13
rszrama commentedOk, thanks for the tip. Something for us to recommend to people reporting the problem in the future.
Comment #14
bbinkovitz commentedI experience this error as well, and just to be clear I did NOT, repeat, DID NOT tamper with the database manually. At all. Ever.
Comment #15
murzSometimes I got this error too on Drupal Commerce 1.4 with popular site (about 2000 unique users per day), but not often, about 1 time with 100 orders.
I check my table commerce_line_item and find no errors, Autoincrement value also in normal state.
Maybe this happens where at the same time two users add products to card? And script checks last free id, do some calculations and when it try to save, other user already occupy this id?
Comment #16
murzPossible duplicate of this issue is #1895652: PDOException: Duplicate entry commerce_line_item
Comment #17
delta commentedGot this error too with drupal commerce 1.3 and drupal commerce 1.5 (after upgrading).
This happens randomly on my shop, for commerce_order, commerce_line_item and commerce_customer_profile.
Comment #18
edboost commentedLooks like I'm getting the same exact error -- although it's brand new on a site that was working fine. And, I'm getting it for anonymous users and admin on all products.
It's interesting, rules are triggering (I've set up a message to show when anonymous users add to cart, advising them to log in), but the item does not get added.
I tried Commerce Repair, but that does not seem to have helped.
I have not messed with the database manually either.
Has anyone figured out a fix for this?
Comment #19
edboost commentedAnother possible solution: set the base URL
Background: A few months ago we set up Boost module and a few other measures to try to limit the database time that spammers were using.
One thing we did was set the URL to www.oursite.org (it used to be oursite.org).
This change has led to all kinds of weird unanticipated problems (mostly with Civicrm -- until I reset the base URL in the civicrm setttings).
So.. on a whim, I went to the main settings.php file for this site (which is part of a multi-site install) and set the (optional) base URL to www.oursite.org.
Voila... now Add to Cart works for all users.
Perhaps our issue was different from everyone else's but it might be worth a try for people who find other solutions aren't working.
Comment #20
Egan7 commentedI'm getting this issue too but I have figured out that it might be due to the fact that old products are still in the basket (even though they do not appear).
Here are two ways that I ended up having the same issue:
1. Add a product to your basket
2. Delete it
3. Add the product back to the basket
1. Add a product to your basket and purchase the product
2. Basket should show as empty
3. Add the product you bought back into your basket
I have attached an image showing old product still showing on the lightbox cart thing. the £80 product is actually in the basket. The £0.10 ITM-easy product is a product purchased by this user and is not in the basket. If I try to add £0.10 ITM-esay product to the cart/basket I get the 'PDOException...' error.
Is there away of deleting these ghost products fully from the basket?
Comment #21
nodecode commentedI came across this error (from the original message). It made me question whether or not I was wise to choose the commerce module in the first place since I suddenly got this after 3 months of development, and just before I'm about ready to launch...
Anyway I solved it by:
1. disabling any module via the UI (seriously ANY module will do)
2. uninstalling that module via the UI
3. re-enabling that module via the UI
Somehow this slapped some sense into the database and everything appears to be working again. Boy I hope I don't see this ugly error again.
Comment #22
nodecode commentedI should mention that, as rszrama suggested in #3, my error was indeed a result of directly editing the database at a much earlier point in time.
The irony here is that rszrama also was the one who suggested users edit the db directly if they want to start their order number incrementing at a higher number than 1: http://www.drupalcommerce.org/questions/3172/how-can-i-change-starting-o...
Comment #23
Jooblay.net commentedWe have read all the comments on this issue but it does not seem clear what the issues is caused from? It seems very spotty:( No clear sign as to actually what caused this and what could fix it....
We only receive this PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '47' for key 1: INSERT INTO {commerce_order_confirm} when adding product through views module generated pages such as a catalog.
Comment #24
SharonD214@aol.com commentedI'm seeing this on a site I just added Commerce (7.x.-1.8) to, I haven't done anything but activate the module and then try to add a new product. Does anyone have any ideas?
Sharon
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'commerce_product-2-0-0-und' for key 'PRIMARY': INSERT INTO {field_data_commerce_price} (entity_type, entity_id, revision_id, bundle, delta, language, commerce_price_amount, commerce_price_currency_code, commerce_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_product [:db_insert_placeholder_1] => 2 [:db_insert_placeholder_2] => 2 [:db_insert_placeholder_3] => product [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 1600000 [:db_insert_placeholder_7] => USD [:db_insert_placeholder_8] => a:1:{s:10:"components";a:0:{}} ) in field_sql_storage_field_storage_write() (line 451 of C:...Sites\drupal\modules\field\modules\field_sql_storage\field_sql_storage.module)
OK - I resolved this after deactivitating everything but Commerce and product submodules and then re-enabling, go figure...
Comment #25
mustafa.ata commentedWell, I got this error while creating nodes programmatically in drupal 7. Actually this happened because of inconsistent data present in CCK fields, revision data and node data.
I got the solution by truncateding all the tables related to fields and then ran the script. It worked.44
I hope it will help someone.
Ata
Comment #26
tolstoydotcomI got this error on a D7 Ubercart to D7 Commerce migration. I hadn't done any direct db manipulation that I think would be related to this issue. I had programmatically created hundreds of commerce_coupon coupons, and the first time that ran it errored out due to bad line endings in the text file containing the coupon codes. I then ran it again, not creating the coupons I'd already created. I'd also programmatically deleted some existing nodes. So, I suspect this is due to one of those.
In any case, I ran this:
I then ran this:
ALTER TABLE commerce_order AUTO_INCREMENT = 2000;I don't know why auto_increment was off, but that seems to have fixed it. I'll have to check all the other tables to make sure they don't have similar problems. Needless to say, changing the auto_increment value could have unforeseen side-effects so use with caution.
Comment #26.0
tolstoydotcomFixed sentence.
Comment #27
junetellain626 commentedIf you're using Commerce Product Option, it could be related to this issue -> https://drupal.org/node/1886140.
Comment #28
thanhkha159684 commentedHey everyone i found that the problem is the orders being deleted but in another table relate with these order still have data that not delete. so that the data is not insert to database becase the PRIMARY KEY, so i have empty by phpmyadmin all table related with order table. Remember that backup the database and go to recent log mes to check the error in site. good look everyone!
Comment #29
daddeptr commentedHi there,
I guess this has been addressed and solved by now, but I managed to resolve this without deleting or refreshing anything: what worked for me was simple adding the condition on the db_update call. You make sure to match the primary key of the database entry you want to update.
$new_entry = db_update( 'table_name' )
-> fields( $array_changes ) -> condition( 'my_primary_key', $array_changes['my_primary_key'], '=') -> execute();
Hope it helps.
Comment #30
-Mania- commented@daddeptr: This hasn't been resolved yet. Where did you add your code exactly?
Comment #31
l_holmes commentedMight not be the perfect solution to this, but I got around the issue by modifying the auto_increment in the commerce_order table. Changing this to a number bigger than your largest order ID should stop the problems.
ALTER TABLE `commerce_order` AUTO_INCREMENT = 1000;https://drupalcommerce.org/questions/3172/how-can-i-change-starting-orde...