timmyomahony / craft-matrix-field-preview

Configure a screenshot preview for all your matrix field blocks, giving your clients a better publishing experience.
https://plugins.craftcms.com/matrix-field-preview
Other
16 stars 4 forks source link

Database Exception when attempting to load the Matrix Block Types settings page #61

Closed petehjfd closed 2 years ago

petehjfd commented 3 years ago

Hi

I just added a new block type to a matrix field. This caused the matrix field's 'Add block' button to fallback to the Craft default (presumably because I haven't added a preview image for the new field yet? Although I'm sure that didn't used to happen).

So I went to the plugin settings to upload a preview image, but I'm getting a General error: 1364 Field 'siteId' doesn't have a default value error when loading the Matrix Block Types settings page.

Craft version: 3.6.5.1 Matrix Field Preview version: 1.2.3

Here's the stacktrace:

PDOException: SQLSTATE[HY000]: General error: 1364 Field 'siteId' doesn't have a default value in /Users/pete/www/saracen/vendor/yiisoft/yii2/db/Command.php:1299
Stack trace:
#0 /Users/pete/www/saracen/vendor/yiisoft/yii2/db/Command.php(1299): PDOStatement->execute()
#1 /Users/pete/www/saracen/vendor/yiisoft/yii2/db/Command.php(1099): yii\db\Command->internalExecute('INSERT INTO `ma...')
#2 /Users/pete/www/saracen/vendor/yiisoft/yii2/db/Schema.php(433): yii\db\Command->execute()
#3 /Users/pete/www/saracen/vendor/yiisoft/yii2/db/ActiveRecord.php(600): yii\db\Schema->insert('{{%matrixfieldp...', Array)
#4 /Users/pete/www/saracen/vendor/yiisoft/yii2/db/ActiveRecord.php(566): yii\db\ActiveRecord->insertInternal(NULL)
#5 /Users/pete/www/saracen/vendor/yiisoft/yii2/db/BaseActiveRecord.php(678): yii\db\ActiveRecord->insert(true, NULL)
#6 /Users/pete/www/saracen/vendor/weareferal/matrix-field-preview/src/services/BaseBlockTypeConfigService.php(95): yii\db\BaseActiveRecord->save()
#7 /Users/pete/www/saracen/vendor/weareferal/matrix-field-preview/src/controllers/SettingsController.php(152): weareferal\matrixfieldpreview\services\BaseBlockTypeConfigService->getOrCreateByFieldHandle('productAddition...')
#8 /Users/pete/www/saracen/vendor/weareferal/matrix-field-preview/src/controllers/SettingsController.php(118): weareferal\matrixfieldpreview\controllers\SettingsController->_actionBlockTypes(Object(weareferal\matrixfieldpreview\services\MatrixBlockTypeConfigService), Object(weareferal\matrixfieldpreview\services\MatrixFieldConfigService), 'matrix-field-pr...')
#9 [internal function]: weareferal\matrixfieldpreview\controllers\SettingsController->actionMatrixBlockTypes()
#10 /Users/pete/www/saracen/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#11 /Users/pete/www/saracen/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#12 /Users/pete/www/saracen/vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction('matrix-block-ty...', Array)
#13 /Users/pete/www/saracen/vendor/yiisoft/yii2/base/Module.php(534): craft\web\Controller->runAction('matrix-block-ty...', Array)
#14 /Users/pete/www/saracen/vendor/craftcms/cms/src/web/Application.php(274): yii\base\Module->runAction('matrix-field-pr...', Array)
#15 /Users/pete/www/saracen/vendor/yiisoft/yii2/web/Application.php(104): craft\web\Application->runAction('matrix-field-pr...', Array)
#16 /Users/pete/www/saracen/vendor/craftcms/cms/src/web/Application.php(259): yii\web\Application->handleRequest(Object(craft\web\Request))
#17 /Users/pete/www/saracen/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))
#18 /Users/pete/www/saracen/web/index.php(22): yii\base\Application->run()
#19 /Users/pete/.composer/vendor/laravel/valet/server.php(214): require('/Users/pete/www...')
#20 {main}

Next yii\db\Exception: SQLSTATE[HY000]: General error: 1364 Field 'siteId' doesn't have a default value
The SQL being executed was: INSERT INTO `matrixfieldpreview_blocktypes_config` (`description`, `fieldId`, `blockTypeId`, `dateCreated`, `dateUpdated`, `uid`) VALUES ('', 216, 20, '2021-02-15 11:56:48', '2021-02-15 11:56:48', '94c2019e-6a83-4667-bec7-1d2c48bed9aa') in /Users/pete/www/saracen/vendor/yiisoft/yii2/db/Schema.php:678
Stack trace:
#0 /Users/pete/www/saracen/vendor/yiisoft/yii2/db/Command.php(1304): yii\db\Schema->convertException(Object(PDOException), 'INSERT INTO `ma...')
#1 /Users/pete/www/saracen/vendor/yiisoft/yii2/db/Command.php(1099): yii\db\Command->internalExecute('INSERT INTO `ma...')
#2 /Users/pete/www/saracen/vendor/yiisoft/yii2/db/Schema.php(433): yii\db\Command->execute()
#3 /Users/pete/www/saracen/vendor/yiisoft/yii2/db/ActiveRecord.php(600): yii\db\Schema->insert('{{%matrixfieldp...', Array)
#4 /Users/pete/www/saracen/vendor/yiisoft/yii2/db/ActiveRecord.php(566): yii\db\ActiveRecord->insertInternal(NULL)
#5 /Users/pete/www/saracen/vendor/yiisoft/yii2/db/BaseActiveRecord.php(678): yii\db\ActiveRecord->insert(true, NULL)
#6 /Users/pete/www/saracen/vendor/weareferal/matrix-field-preview/src/services/BaseBlockTypeConfigService.php(95): yii\db\BaseActiveRecord->save()
#7 /Users/pete/www/saracen/vendor/weareferal/matrix-field-preview/src/controllers/SettingsController.php(152): weareferal\matrixfieldpreview\services\BaseBlockTypeConfigService->getOrCreateByFieldHandle('productAddition...')
#8 /Users/pete/www/saracen/vendor/weareferal/matrix-field-preview/src/controllers/SettingsController.php(118): weareferal\matrixfieldpreview\controllers\SettingsController->_actionBlockTypes(Object(weareferal\matrixfieldpreview\services\MatrixBlockTypeConfigService), Object(weareferal\matrixfieldpreview\services\MatrixFieldConfigService), 'matrix-field-pr...')
#9 [internal function]: weareferal\matrixfieldpreview\controllers\SettingsController->actionMatrixBlockTypes()
#10 /Users/pete/www/saracen/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#11 /Users/pete/www/saracen/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#12 /Users/pete/www/saracen/vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction('matrix-block-ty...', Array)
#13 /Users/pete/www/saracen/vendor/yiisoft/yii2/base/Module.php(534): craft\web\Controller->runAction('matrix-block-ty...', Array)
#14 /Users/pete/www/saracen/vendor/craftcms/cms/src/web/Application.php(274): yii\base\Module->runAction('matrix-field-pr...', Array)
#15 /Users/pete/www/saracen/vendor/yiisoft/yii2/web/Application.php(104): craft\web\Application->runAction('matrix-field-pr...', Array)
#16 /Users/pete/www/saracen/vendor/craftcms/cms/src/web/Application.php(259): yii\web\Application->handleRequest(Object(craft\web\Request))
#17 /Users/pete/www/saracen/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))
#18 /Users/pete/www/saracen/web/index.php(22): yii\base\Application->run()
#19 /Users/pete/.composer/vendor/laravel/valet/server.php(214): require('/Users/pete/www...')
#20 {main}
Additional Information:
Array
(
    [0] => HY000
    [1] => 1364
    [2] => Field 'siteId' doesn't have a default value
)
timmyomahony commented 3 years ago

@petehjfd seems like a migration problem. Let me have a closer look and I'll get back to you

timmyomahony commented 2 years ago

Apologies for the delay in following up on this. I imagine this issue was either resolved or you moved on. I've been on a bit of an unexpected hiatus with regard to Craft development but have been trying to get everything back up to speed.

With that in mind, I've created a new 3.0.0 release with a number of big improvements, including some migrations that may fix this issue with siteId. You can see #73 for more. Hopefully you'll be able to give this another go.

I'm going to close this issue for the moment, but if you need more help please let me know and I'll follow up.