Body: <p>Anybody know how to resolve the following when using Craft Commerce?</p>
  <p>Running the command <code>craft gc/run</code> throws an error.</p>
  <pre><code>Next yii\db\Exception: SQLSTATE[HY000]: General error: 1093 You can't specify target table 'commerce_customers' for update in FROM clause
  The SQL being executed was: DELETE FROM `commerce_customers` WHERE `id` IN (SELECT `customers`.`id` AS `id`
  FROM `commerce_customers` `customers`
  LEFT JOIN `commerce_orders` `orders` ON `customers`.`id` = `orders`.`customerId`
  WHERE (`orders`.`customerId` IS NULL) AND (`customers`.`userId` IS NULL)) in /vendor/yiisoft/yii2/db/Schema.php:677
  Stack trace:
  #0 /vendor/yiisoft/yii2/db/Command.php(1298): yii\db\Schema-&gt;convertException(Object(PDOException), 'DELETE FROM `co...')
  #1 /vendor/yiisoft/yii2/db/Command.php(1093): yii\db\Command-&gt;internalExecute('DELETE FROM `co...')
  #2 /vendor/craftcms/commerce/src/services/Customers.php(383): yii\db\Command-&gt;execute()
  #3 /vendor/craftcms/commerce/src/Plugin.php(670): craft\commerce\services\Customers-&gt;purgeOrphanedCustomers()
  #4 [internal function]: craft\commerce\Plugin-&gt;craft\commerce\{closure}(Object(yii\base\Event))
  #5 /vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(yii\base\Event))
  #6 /vendor/yiisoft/yii2/base/Component.php(636): yii\base\Event::trigger('craft\\services\\...', 'run', Object(yii\base\Event))
  #7 /vendor/craftcms/cms/src/services/Gc.php(74): yii\base\Component-&gt;trigger('run')
  #8 /vendor/craftcms/cms/src/console/controllers/GcController.php(56): craft\services\Gc-&gt;run(true)
  #9 [internal function]: craft\console\controllers\GcController-&gt;actionRun()
  #10 /vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
  #11 /vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction-&gt;runWithParams(Array)
  #12 /vendor/yiisoft/yii2/console/Controller.php(179): yii\base\Controller-&gt;runAction('run', Array)
  #13 /vendor/craftcms/cms/src/console/Controller.php(188): yii\console\Controller-&gt;runAction('run', Array)
  #14 /vendor/yiisoft/yii2/base/Module.php(528): craft\console\Controller-&gt;runAction('run', Array)
  #15 /vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module-&gt;runAction('gc/run', Array)
  #16 /vendor/craftcms/cms/src/console/Application.php(88): yii\console\Application-&gt;runAction('gc/run', Array)
  #17 /vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application-&gt;runAction('gc/run', Array)
  #18 /vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application-&gt;handleRequest(Object(craft\console\Request))
  #19 /craft(23): yii\base\Application-&gt;run()
  #20 {main}
  Additional Information:
  Array
  (
      [0] =&gt; HY000
      [1] =&gt; 1093
      [2] =&gt; You can't specify target table 'commerce_customers' for update in FROM clause
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-24T19:36:35.613Z
Comments.Text: This sounds like a bug - I'd suggest filing it on https://github.com/craftcms/commerce/issues along with that stack trace and the version of Craft and Commerce you're seeing it on. Going to go ahead and vote to close here.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-01-04T16:08:27.340Z
Comments.Text: I'm seeing this error too, is it reported yet?
Comments.UserDisplayName: James Smith
Tags: <plugin-craftcommerce>
Title: Running garbage collection with commerce errors
ThreadText: # Running garbage collection with commerce errors
  
  (Asked by: username_0 on 2020-12-24)
  
  Anybody know how to resolve the following when using Craft Commerce?
  
  Running the command `craft gc/run` throws an error.
  
  ```
  Next yii\db\Exception: SQLSTATE[HY000]: General error: 1093 You can't specify target table 'commerce_customers' for update in FROM clause
  The SQL being executed was: DELETE FROM `commerce_customers` WHERE `id` IN (SELECT `customers`.`id` AS `id`
  FROM `commerce_customers` `customers`
  LEFT JOIN `commerce_orders` `orders` ON `customers`.`id` = `orders`.`customerId`
  WHERE (`orders`.`customerId` IS NULL) AND (`customers`.`userId` IS NULL)) in /vendor/yiisoft/yii2/db/Schema.php:677
  Stack trace:
  #0 /vendor/yiisoft/yii2/db/Command.php(1298): yii\db\Schema->convertException(Object(PDOException), 'DELETE FROM `co...')
  #1 /vendor/yiisoft/yii2/db/Command.php(1093): yii\db\Command->internalExecute('DELETE FROM `co...')
  #2 /vendor/craftcms/commerce/src/services/Customers.php(383): yii\db\Command->execute()
  #3 /vendor/craftcms/commerce/src/Plugin.php(670): craft\commerce\services\Customers->purgeOrphanedCustomers()
  #4 [internal function]: craft\commerce\Plugin->craft\commerce\{closure}(Object(yii\base\Event))
  #5 /vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(yii\base\Event))
  #6 /vendor/yiisoft/yii2/base/Component.php(636): yii\base\Event::trigger('craft\\services\\...', 'run', Object(yii\base\Event))
  #7 /vendor/craftcms/cms/src/services/Gc.php(74): yii\base\Component->trigger('run')
  #8 /vendor/craftcms/cms/src/console/controllers/GcController.php(56): craft\services\Gc->run(true)
  #9 [internal function]: craft\console\controllers\GcController->actionRun()
  #10 /vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
  #11 /vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams(Array)
  #12 /vendor/yiisoft/yii2/console/Controller.php(179): yii\base\Controller->runAction('run', Array)
  #13 /vendor/craftcms/cms/src/console/Controller.php(188): yii\console\Controller->runAction('run', Array)
  #14 /vendor/yiisoft/yii2/base/Module.php(528): craft\console\Controller->runAction('run', Array)
  #15 /vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('gc/run', Array)
  #16 /vendor/craftcms/cms/src/console/Application.php(88): yii\console\Application->runAction('gc/run', Array)
  #17 /vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('gc/run', Array)
  #18 /vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
  #19 /craft(23): yii\base\Application->run()
  #20 {main}
  Additional Information:
  Array
  (
      [0] => HY000
      [1] => 1093
      [2] => You can't specify target table 'commerce_customers' for update in FROM clause
  
  ```
  
  **Tags:** plugin-craftcommerce
  
  > **Comments:**
  > **username_1**: This sounds like a bug - I'd suggest filing it on https://github.com/craftcms/commerce/issues along with that stack trace and the version of Craft and Commerce you're seeing it on. Going to go ahead and vote to close here.  
  > **username_2**: I'm seeing this error too, is it reported yet?  
  
  ---
  
  ## 0 answers
  
  