craftcms / commerce

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

[5.x]: Integrity constraint violation: 1048 Column 'shippingCategoryId' cannot be null #3521

Closed bartdigitalpulse closed 1 month ago

bartdigitalpulse commented 1 month ago

What happened?

Description

Going to /admin/commerce/donations throws an exception. It's a fresh commerce setup and haven't added/changed tax or shipping categories.

Stack trace:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'shippingCategoryId' cannot be null in /var/www/html/vendor/yiisoft/yii2/db/Command.php:1302
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1302): PDOStatement->execute()
#1 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute('INSERT INTO `co...')
#2 /var/www/html/vendor/yiisoft/yii2/db/Schema.php(431): yii\db\Command->execute()
#3 /var/www/html/vendor/yiisoft/yii2/db/ActiveRecord.php(604): yii\db\Schema->insert('{{%commerce_pur...', Array)
#4 /var/www/html/vendor/yiisoft/yii2/db/ActiveRecord.php(570): yii\db\ActiveRecord->insertInternal(NULL)
#5 /var/www/html/vendor/yiisoft/yii2/db/BaseActiveRecord.php(676): yii\db\ActiveRecord->insert(false, NULL)
#6 /var/www/html/vendor/craftcms/commerce/src/elements/Donation.php(281): yii\db\BaseActiveRecord->save(false)
#7 /var/www/html/vendor/illuminate/collections/Traits/EnumeratesValues.php(240): craft\commerce\elements\Donation->craft\commerce\elements\{closure}(Object(craft\commerce\models\Store), 1)
#8 /var/www/html/vendor/craftcms/commerce/src/elements/Donation.php(262): Illuminate\Support\Collection->each(Object(Closure))
#9 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(3673): craft\commerce\elements\Donation->afterSave(true)
#10 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1169): craft\services\Elements->craft\services\{closure}()
#11 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(3489): craft\services\Elements->ensureBulkOp(Object(Closure))
#12 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1250): craft\services\Elements->_saveElementInternal(Object(craft\commerce\elements\Donation), true, false, NULL, Array, false, false, true)
#13 /var/www/html/vendor/craftcms/commerce/src/controllers/DonationsController.php(41): craft\services\Elements->saveElement(Object(craft\commerce\elements\Donation))
#14 [internal function]: craft\commerce\controllers\DonationsController->actionEdit()
#15 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#16 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#17 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('edit', Array)
#18 /var/www/html/vendor/craftcms/cms/src/web/Application.php(349): yii\base\Module->runAction('commerce/donati...', Array)
#19 /var/www/html/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('commerce/donati...', Array)
#20 /var/www/html/vendor/craftcms/cms/src/web/Application.php(317): yii\web\Application->handleRequest(Object(craft\web\Request))
#21 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#22 /var/www/html/web/index.php(12): yii\base\Application->run()
#23 {main}

Next yii\db\IntegrityException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'shippingCategoryId' cannot be null
The SQL being executed was: INSERT INTO `commerce_purchasables_stores` (`purchasableId`, `storeId`, `basePrice`, `basePromotionalPrice`, `stock`, `inventoryTracked`, `minQty`, `maxQty`, `promotable`, `availableForPurchase`, `freeShipping`, `shippingCategoryId`, `dateCreated`, `dateUpdated`, `uid`) VALUES (6628, 2, 0, NULL, NULL, 0, NULL, NULL, 0, 0, 1, NULL, '2024-05-24 12:46:54', '2024-05-24 12:46:54', 'd6934c31-a883-4921-9031-ea4d7ba709c5') in /var/www/html/vendor/yiisoft/yii2/db/Schema.php:676
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'INSERT INTO `co...')
#1 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute('INSERT INTO `co...')
#2 /var/www/html/vendor/yiisoft/yii2/db/Schema.php(431): yii\db\Command->execute()
#3 /var/www/html/vendor/yiisoft/yii2/db/ActiveRecord.php(604): yii\db\Schema->insert('{{%commerce_pur...', Array)
#4 /var/www/html/vendor/yiisoft/yii2/db/ActiveRecord.php(570): yii\db\ActiveRecord->insertInternal(NULL)
#5 /var/www/html/vendor/yiisoft/yii2/db/BaseActiveRecord.php(676): yii\db\ActiveRecord->insert(false, NULL)
#6 /var/www/html/vendor/craftcms/commerce/src/elements/Donation.php(281): yii\db\BaseActiveRecord->save(false)
#7 /var/www/html/vendor/illuminate/collections/Traits/EnumeratesValues.php(240): craft\commerce\elements\Donation->craft\commerce\elements\{closure}(Object(craft\commerce\models\Store), 1)
#8 /var/www/html/vendor/craftcms/commerce/src/elements/Donation.php(262): Illuminate\Support\Collection->each(Object(Closure))
#9 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(3673): craft\commerce\elements\Donation->afterSave(true)
#10 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1169): craft\services\Elements->craft\services\{closure}()
#11 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(3489): craft\services\Elements->ensureBulkOp(Object(Closure))
#12 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1250): craft\services\Elements->_saveElementInternal(Object(craft\commerce\elements\Donation), true, false, NULL, Array, false, false, true)
#13 /var/www/html/vendor/craftcms/commerce/src/controllers/DonationsController.php(41): craft\services\Elements->saveElement(Object(craft\commerce\elements\Donation))
#14 [internal function]: craft\commerce\controllers\DonationsController->actionEdit()
#15 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#16 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#17 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('edit', Array)
#18 /var/www/html/vendor/craftcms/cms/src/web/Application.php(349): yii\base\Module->runAction('commerce/donati...', Array)
#19 /var/www/html/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('commerce/donati...', Array)
#20 /var/www/html/vendor/craftcms/cms/src/web/Application.php(317): yii\web\Application->handleRequest(Object(craft\web\Request))
#21 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#22 /var/www/html/web/index.php(12): yii\base\Application->run()
#23 {main}
Additional Information:
Array
(
    [0] => 23000
    [1] => 1048
    [2] => Column 'shippingCategoryId' cannot be null
)

Craft CMS version

Craft Pro 5.1.5

Craft Commerce version

5.0.7

PHP version

8.2.18

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 1 month ago

PT-1759 [5.x]: Integrity constraint violation: 1048 Column 'shippingCategoryId' cannot be null

lukeholder commented 1 month ago

Thanks for reporting. The fix will be in the next release.

To get the fix early, change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "5.x-dev#11ce1a4310f176883a80fbd31078cbc81d3494a1 as 5.0.8",
  "...": "..."
}

Then run composer update.

You might need to resave your stores before trying to load the donation settings again.

We will update this ticket once we make the next release public. Thanks!