craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
226 stars 170 forks source link

[5.x]: Cannot re-enable Commerce plugin, "Column not found" exception. #3741

Open sammcqueen opened 2 hours ago

sammcqueen commented 2 hours ago

What happened?

Description

Attempting to enable the Commerce plugin via the control panel gives a 'Database Exception' error, meaning it cannot be uninstalled.

I believe this could be linked to the fact that the site was previously on Craft 4 with the plugin installed and enabled, however, some time prior to the upgrade to Craft 5 the plugin was disabled and the upgrade then carried out. Would this have meant the Commerce plugin missed out on some important DB migrations?

With the site now successfully running Craft 5, the plugin cannot be re-enabled without throwing the below exception. I'm doing this in an attempt to completely remove Commerce, so if there is a workaround that would allow the plugin to be removed a different way that would be a solution.

The DB also has many additional tables with sequential numbers such as 'p_co_old10', 'p_co_old11', 'p_co_old12' and 'p_com_old1', 'p_com_old2', 'p_com_old3', etc.

Stacktrace

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'handle' in 'field list' in /var/www/html/craft/vendor/yiisoft/yii2/db/Command.php:1320
Stack trace:
#0 /var/www/html/craft/vendor/yiisoft/yii2/db/Command.php(1320): PDOStatement->execute()
#1 /var/www/html/craft/vendor/yiisoft/yii2/db/Command.php(1186): yii\db\Command->internalExecute('SELECT `handle`...')
#2 /var/www/html/craft/vendor/yiisoft/yii2/db/Command.php(417): yii\db\Command->queryInternal('fetchAll', NULL)
#3 /var/www/html/craft/vendor/yiisoft/yii2/db/Query.php(249): yii\db\Command->queryAll()
#4 /var/www/html/craft/vendor/craftcms/cms/src/db/Query.php(292): yii\db\Query->all(NULL)
#5 /var/www/html/craft/vendor/craftcms/commerce/src/services/Stores.php(120): craft\db\Query->all()
#6 /var/www/html/craft/vendor/craftcms/commerce/src/services/Stores.php(191): craft\commerce\services\Stores->_loadAllStores()
#7 /var/www/html/craft/vendor/craftcms/commerce/src/services/Stores.php(150): craft\commerce\services\Stores->getStoreBySiteId(1)
#8 /var/www/html/craft/vendor/craftcms/commerce/src/services/Carts.php(81): craft\commerce\services\Stores->getCurrentStore()
#9 /var/www/html/craft/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\commerce\services\Carts->init()
#10 [internal function]: yii\base\BaseObject->__construct(Array)
#11 /var/www/html/craft/vendor/yiisoft/yii2/di/Container.php(411): ReflectionClass->newInstanceArgs(Array)
#12 /var/www/html/craft/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\commerce\\...', Array, Array)
#13 /var/www/html/craft/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\commerce\\...', Array, Array)
#14 /var/www/html/craft/vendor/yiisoft/yii2/di/ServiceLocator.php(137): yii\BaseYii::createObject(Array)
#15 /var/www/html/craft/vendor/yiisoft/yii2/base/Module.php(769): yii\di\ServiceLocator->get('carts', false)
#16 /var/www/html/craft/vendor/craftcms/commerce/src/plugin/Services.php(108): yii\base\Module->get('carts')
#17 /var/www/html/craft/vendor/craftcms/commerce/src/Plugin.php(744): craft\commerce\Plugin->getCarts()
#18 /var/www/html/craft/vendor/craftcms/commerce/src/Plugin.php(294): craft\commerce\Plugin->_registerCraftEventListeners()
#19 /var/www/html/craft/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\commerce\Plugin->init()
#20 /var/www/html/craft/vendor/yiisoft/yii2/base/Module.php(161): yii\base\BaseObject->__construct(Array)
#21 /var/www/html/craft/vendor/craftcms/cms/src/base/Plugin.php(122): yii\base\Module->__construct('commerce', Object(craft\web\Application), Array)
#22 [internal function]: craft\base\Plugin->__construct('commerce', Object(craft\web\Application), Array)
#23 /var/www/html/craft/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
#24 /var/www/html/craft/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\commerce\\...', Array, Array)
#25 /var/www/html/craft/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\commerce\\...', Array, Array)
#26 /var/www/html/craft/vendor/craftcms/cms/src/Craft.php(70): yii\BaseYii::createObject(Array, Array)
#27 /var/www/html/craft/vendor/craftcms/cms/src/services/Plugins.php(948): Craft::createObject(Array, Array)
#28 /var/www/html/craft/vendor/craftcms/cms/src/services/Plugins.php(392): craft\services\Plugins->createPlugin('commerce', Array)
#29 /var/www/html/craft/vendor/craftcms/cms/src/controllers/PluginsController.php(119): craft\services\Plugins->enablePlugin('commerce')
#30 [internal function]: craft\controllers\PluginsController->actionEnablePlugin()
#31 /var/www/html/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#32 /var/www/html/craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#33 /var/www/html/craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('enable-plugin', Array)
#34 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(350): yii\base\Module->runAction('plugins/enable-...', Array)
#35 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(649): craft\web\Application->runAction('plugins/enable-...', Array)
#36 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(312): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#37 /var/www/html/craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#38 /var/www/html/public_html/index.php(22): yii\base\Application->run()
#39 {main}

Next yii\db\Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'handle' in 'field list'
The SQL being executed was: SELECT `handle`, `id`, `name`, `primary`, `uid`
FROM `p_commerce_stores` in /var/www/html/craft/vendor/yiisoft/yii2/db/Schema.php:676
Stack trace:
#0 /var/www/html/craft/vendor/yiisoft/yii2/db/Command.php(1325): yii\db\Schema->convertException(Object(PDOException), 'SELECT `handle`...')
#1 /var/www/html/craft/vendor/yiisoft/yii2/db/Command.php(1186): yii\db\Command->internalExecute('SELECT `handle`...')
#2 /var/www/html/craft/vendor/yiisoft/yii2/db/Command.php(417): yii\db\Command->queryInternal('fetchAll', NULL)
#3 /var/www/html/craft/vendor/yiisoft/yii2/db/Query.php(249): yii\db\Command->queryAll()
#4 /var/www/html/craft/vendor/craftcms/cms/src/db/Query.php(292): yii\db\Query->all(NULL)
#5 /var/www/html/craft/vendor/craftcms/commerce/src/services/Stores.php(120): craft\db\Query->all()
#6 /var/www/html/craft/vendor/craftcms/commerce/src/services/Stores.php(191): craft\commerce\services\Stores->_loadAllStores()
#7 /var/www/html/craft/vendor/craftcms/commerce/src/services/Stores.php(150): craft\commerce\services\Stores->getStoreBySiteId(1)
#8 /var/www/html/craft/vendor/craftcms/commerce/src/services/Carts.php(81): craft\commerce\services\Stores->getCurrentStore()
#9 /var/www/html/craft/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\commerce\services\Carts->init()
#10 [internal function]: yii\base\BaseObject->__construct(Array)
#11 /var/www/html/craft/vendor/yiisoft/yii2/di/Container.php(411): ReflectionClass->newInstanceArgs(Array)
#12 /var/www/html/craft/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\commerce\\...', Array, Array)
#13 /var/www/html/craft/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\commerce\\...', Array, Array)
#14 /var/www/html/craft/vendor/yiisoft/yii2/di/ServiceLocator.php(137): yii\BaseYii::createObject(Array)
#15 /var/www/html/craft/vendor/yiisoft/yii2/base/Module.php(769): yii\di\ServiceLocator->get('carts', false)
#16 /var/www/html/craft/vendor/craftcms/commerce/src/plugin/Services.php(108): yii\base\Module->get('carts')
#17 /var/www/html/craft/vendor/craftcms/commerce/src/Plugin.php(744): craft\commerce\Plugin->getCarts()
#18 /var/www/html/craft/vendor/craftcms/commerce/src/Plugin.php(294): craft\commerce\Plugin->_registerCraftEventListeners()
#19 /var/www/html/craft/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\commerce\Plugin->init()
#20 /var/www/html/craft/vendor/yiisoft/yii2/base/Module.php(161): yii\base\BaseObject->__construct(Array)
#21 /var/www/html/craft/vendor/craftcms/cms/src/base/Plugin.php(122): yii\base\Module->__construct('commerce', Object(craft\web\Application), Array)
#22 [internal function]: craft\base\Plugin->__construct('commerce', Object(craft\web\Application), Array)
#23 /var/www/html/craft/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
#24 /var/www/html/craft/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\commerce\\...', Array, Array)
#25 /var/www/html/craft/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\commerce\\...', Array, Array)
#26 /var/www/html/craft/vendor/craftcms/cms/src/Craft.php(70): yii\BaseYii::createObject(Array, Array)
#27 /var/www/html/craft/vendor/craftcms/cms/src/services/Plugins.php(948): Craft::createObject(Array, Array)
#28 /var/www/html/craft/vendor/craftcms/cms/src/services/Plugins.php(392): craft\services\Plugins->createPlugin('commerce', Array)
#29 /var/www/html/craft/vendor/craftcms/cms/src/controllers/PluginsController.php(119): craft\services\Plugins->enablePlugin('commerce')
#30 [internal function]: craft\controllers\PluginsController->actionEnablePlugin()
#31 /var/www/html/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#32 /var/www/html/craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#33 /var/www/html/craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('enable-plugin', Array)
#34 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(350): yii\base\Module->runAction('plugins/enable-...', Array)
#35 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(649): craft\web\Application->runAction('plugins/enable-...', Array)
#36 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(312): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#37 /var/www/html/craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#38 /var/www/html/public_html/index.php(22): yii\base\Application->run()
#39 {main}
Additional Information:
Array
(
    [0] => 42S22
    [1] => 1054
    [2] => Unknown column 'handle' in 'field list'
)

Steps to reproduce

  1. Enable Commerce plugin from plugins page in Control Panel.

Expected behavior

Plugin should re-enable to allow uninstall.

Actual behavior

DB exception thrown.

Craft CMS version

5.4.9

Craft Commerce version

5.2.1

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

linear[bot] commented 2 hours ago

PT-2284 [5.x]: Cannot re-enable Commerce plugin, "Column not found" exception.