craftcms / craftcms/cms

[4.x]: Column not found when applying project config (matrix field)

Open
#12,735 3 comments 0 reactions 1 assignee View on GitHub

@i-just is already working on this.

Since Mar 3, 2023.

bug craft4
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

What happened?
Description

I have added a Link Field to an existing Matrix block, working correctly (editing/rendering) in the dev environment on which it was created. Applying project config on another environment fails, with an SQL Column not found error. The migration that's auto-generated appears to be looking for columns on the content table which do not exist (or at least which exist, but are called something slightly different).

Similar to https://github.com/craftcms/cms/issues/9749 and https://github.com/sebastian-lenz/craft-linkfield/issues/163 except this bug is present when applying project config. Is this a Craft issue, or a Plugin issue @sebastian-lenz ?

The pertinent error is Column not found: 1054 Unknown column 'content.field_fullWidthCta_videoUrl' in 'field list' but looking at the SELECT that's generated, the same is happening for other Matrix columns. The Matrix field name is being added to the column name, but that doesn't reflect what's in the database schema (i.e. it contains `content.field_videoUrl, not content.field_fullWidthCta_videoUrl etc.).

Part of the content table structure:
image

The changes in the Matrix block include a new Link Field (sebastian-lenz/craft-linkfield, the plugin installed at the same time. The Craft installation was updated from 3.7 to 4.x a few weeks ago.

Full output of the project-config/apply below.

Steps to reproduce
  1. Add a Link Field to a Matrix block, apply the project-config changes to production server.
Expected behavior

The project-config is applied correctly and the Link Field is present in the Matrix block editor.

Actual behavior

Application of project config fails:

Applying changes from your project config files ...
- removing matrixBlockTypes.38e31717-13d0-4507-9208-97b907246bc6.fields.626ea6a6-4dda-46bf-ac28-33ce80a7ef7b.settings ...
  - updating matrixBlockTypes.38e31717-13d0-4507-9208-97b907246bc6 ...
error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'content.field_fullWidthCta_videoUrl' in 'field list'
The SQL being executed was: SELECT `elements`.`id`, `elements`.`canonicalId`, `elements`.`fieldLayoutId`, `elements`.`uid`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateLastMerged`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_sites`.`id` AS `siteSettingsId`, `elements_sites`.`slug`, `elements_sites`.`siteId`, `elements_sites`.`uri`, `elements_sites`.`enabled` AS `enabledForSite`, `entries`.`sectionId`, `entries`.`typeId`, `entries`.`authorId`, `entries`.`postDate`, `entries`.`expiryDate`, `content`.`id` AS `contentId`, `content`.`title`, `content`.`field_fullWidthCta_videoUrl`, `content`.`field_fullWidthCta_footertext`, `content`.`field_fullWidthCta_headerSelection`, `content`.`field_fullWidthCta_homepageAnimation`, `content`.`field_fullWidthCta_homepageLezButtonsIntro`, `content`.`field_fullWidthCta_linkToAnExternalUrl`, `content`.`field_fullWidthCta_makeSiteGrayscale_imwglwgy`, `content`.`field_fullWidthCta_metaDescription`, `content`.`field_fullWidthCta_metaTags`, `content`.`field_fullWidthCta_seo`, `content`.`field_fullWidthCta_openLinkInNewWindow`, `content`.`field_fullWidthCta_pagecontent`, `content`.`field_fullWidthCta_pagesubtitle`, `content`.`field_fullWidthCta_metaPageTitle`, `content`.`field_fullWidthCta_pagetitle`, `content`.`field_fullWidthCta_showInPrimaryNavigation`, `content`.`field_fullWidthCta_newsSummary`, `content`.`field_fullWidthCta_vrcUnavailable_tbehhjcb`, `structureelements`.`root`, `structureelements`.`lft`, `structureelements`.`rgt`, `structureelements`.`level`, `structureelements`.`structureId`
FROM (SELECT `elements`.`id` AS `elementsId`, `elements_sites`.`id` AS `elementsSitesId`, `content`.`id` AS `contentId`, `structureelements`.`structureId`
FROM `elements` `elements`
INNER JOIN `entries` `entries` ON `entries`.`id` = `elements`.`id`
INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`elementId` = `elements`.`id`
INNER JOIN `content` `content` ON `content`.`elementId` = `elements`.`id`
LEFT JOIN `structureelements` `structureelements` ON (`structureelements`.`elementId` = `elements`.`id`) AND (EXISTS (SELECT *
FROM `structures` use index(primary)
WHERE (`id` = `structureelements`.`structureId`) AND (`dateDeleted` IS NULL)))
WHERE (`entries`.`postDate` > '2023-02-24 10:20:02') AND (`elements`.`archived`=FALSE) AND (`elements`.`dateDeleted` IS NULL) AND (`elements`.`draftId` IS NULL) AND (`elements`.`revisionId` IS NULL)
ORDER BY `postDate`
LIMIT 1) `subquery`
INNER JOIN `elements` `elements` ON `elements`.`id` = `subquery`.`elementsId`
INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`id` = `subquery`.`elementsSitesId`
INNER JOIN `entries` `entries` ON `entries`.`id` = `subquery`.`elementsId`
INNER JOIN `content` `content` ON `content`.`id` = `subquery`.`contentId`
LEFT JOIN `structureelements` `structureelements` ON (`structureelements`.`elementId` = `subquery`.`elementsId`) AND (`structureelements`.`structureId` = `subquery`.`structureId`)
ORDER BY `postDate`

Partial stack trace from console.log:

{
    "trace": [
        "#0 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/db/Command.php(1307): yii\\db\\Schema->convertException()",
        "#1 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/db/Command.php(1168): yii\\db\\Command->internalExecute()",
        "#2 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/db/Command.php(424): yii\\db\\Command->queryInternal()",
        "#3 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/db/Query.php(287): yii\\db\\Command->queryOne()",
        "#4 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/db/Query.php(275): yii\\db\\Query->one()",
        "#5 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1506): craft\\db\\Query->one()",
        "#6 /var/www/vtdocs/tslez/vendor/sebastianlenz/linkfield/src/listeners/ElementListenerState.php(233): craft\\elements\\db\\ElementQuery->one()",
        "#7 /var/www/vtdocs/tslez/vendor/sebastianlenz/linkfield/src/listeners/ElementListenerState.php(153): lenz\\linkfield\\listeners\\ElementListenerState->loadNextEntryChangeDate()",
        "#8 /var/www/vtdocs/tslez/vendor/sebastianlenz/linkfield/src/listeners/ElementListenerState.php(47): lenz\\linkfield\\listeners\\ElementListenerState->reset()",
        "#9 /var/www/vtdocs/tslez/vendor/sebastianlenz/linkfield/src/listeners/ElementListenerState.php(283): lenz\\linkfield\\listeners\\ElementListenerState->__construct()",
        "#10 /var/www/vtdocs/tslez/vendor/sebastianlenz/linkfield/src/fields/LinkField.php(102): lenz\\linkfield\\listeners\\ElementListenerState::getInstance()",
        "#11 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/services/Fields.php(1712): lenz\\linkfield\\fields\\LinkField->afterSave()",
        "#12 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/services/Matrix.php(312): craft\\services\\Fields->applyFieldSave()",
        "#13 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/base/ApplicationTrait.php(1698): craft\\services\\Matrix->handleChangedBlockType()",
        "#14 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/services/ProjectConfig.php(1125): craft\\console\\Application->craft\\base\\{closure}()",
        "#15 [internal function]: craft\\services\\ProjectConfig->handleChangeEvent()",
        "#16 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/base/Component.php(633): call_user_func()",
        "#17 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/models/ProjectConfigData.php(82): yii\\base\\Component->trigger()",
        "#18 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/services/ProjectConfig.php(1115): craft\\models\\ProjectConfigData->commitChanges()",
        "#19 [internal function]: craft\\services\\ProjectConfig->handleChangeEvent()",
        "#20 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/base/Component.php(633): call_user_func()",
        "#21 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/models/ProjectConfigData.php(76): yii\\base\\Component->trigger()",
        "#22 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/services/ProjectConfig.php(1231): craft\\models\\ProjectConfigData->commitChanges()",
        "#23 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/services/ProjectConfig.php(1237): craft\\services\\ProjectConfig->craft\\services\\{closure}()",
        "#24 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/services/ProjectConfig.php(577): craft\\services\\ProjectConfig->_applyChanges()",
        "#25 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/console/controllers/ProjectConfigController.php(303): craft\\services\\ProjectConfig->applyExternalChanges()",
        "#26 [internal function]: craft\\console\\controllers\\ProjectConfigController->actionApply()",
        "#27 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()",
        "#28 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/base/Controller.php(178): yii\\base\\InlineAction->runWithParams()",
        "#29 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/console/Controller.php(180): yii\\base\\Controller->runAction()",
        "#30 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/console/Controller.php(227): yii\\console\\Controller->runAction()",
        "#31 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/base/Module.php(552): craft\\console\\Controller->runAction()",
        "#32 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/console/Application.php(180): yii\\base\\Module->runAction()",
        "#33 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/console/Application.php(90): yii\\console\\Application->runAction()",
        "#34 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/console/Application.php(147): craft\\console\\Application->runAction()",
        "#35 /var/www/vtdocs/tslez/vendor/craftcms/cms/src/console/Application.php(121): yii\\console\\Application->handleRequest()",
        "#36 /var/www/vtdocs/tslez/vendor/yiisoft/yii2/base/Application.php(384): craft\\console\\Application->handleRequest()",
        "#37 /var/www/vtdocs/tslez/craft(22): yii\\base\\Application->run()",
        "#38 {main}"
    ]
}
Craft CMS version

4.3.10

PHP version

8.0.28

Operating system and version

Debian 5.10.158-2

Database type and version

MariaDB 10.5.18

Image driver and version

No response

Installed plugins and versions
  • Blitz 4.3.3
  • Redactor 3.0.3
  • Retcon 2.6.1
  • Retour 4.1.10
  • SEO v4.0.3
  • Super Table 3.0.7
  • Typed link field 2.1.5 (Being added in this update)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.