spicywebau / craft-fieldlabels

Override Craft CMS field labels and instructions in the field layout designer
MIT License
123 stars 9 forks source link

Migration failure on update: Unknown column 'types.maxSiblingBlocks' in 'field list' #56

Closed jamealg closed 4 years ago

jamealg commented 4 years ago

Description

This issue looks very similar to one in the Neo repository https://github.com/spicywebau/craft-neo/issues/382 but slightly different. I just made the big update on our site from Craft CMS 3.4.9 to 3.5.4. Along with the core CMS updates, I'm also updating Neo from 2.6.4 to 2.8.4 and FieldLabels from 1.1.9 to 1.3.1.

Steps to reproduce

I haven't reproduced on a fresh install. But here's the gist:

  1. Start with Craft 3.4.9, Neo 2.6.4, FieldLabels 1.1.9
  2. Perform upgrade to latest versions (Craft 3.5.4, Neo 2.8.4, FieldLabels 1.3.1)
  3. Upgrade fails with this error message:

Database Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'types.maxSiblingBlocks' in 'field list' The SQL being executed was: SELECT types.fieldLayoutId, types.name, types.handle, types.maxBlocks, types.maxSiblingBlocks, types.maxChildBlocks, types.childBlocks, types.topLevel, types.sortOrder, types.uid, fields.uid AS field FROM neoblocktypes types INNER JOIN fields fields ON types.fieldId = fields.id

Migration: spicyweb\fieldlabels\migrations\m200812_104254_craft_3_5_field_layout_transition_part_2

Output:

Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'types.maxSiblingBlocks' in 'field list' The SQL being executed was: SELECT types.fieldLayoutId, types.name, types.handle, types.maxBlocks, types.maxSiblingBlocks, types.maxChildBlocks, types.childBlocks, types.topLevel, types.sortOrder, types.uid, fields.uid AS field FROM neoblocktypes types INNER JOIN fields fields ON types.fieldId = fields.id (/site/src/vendor/yiisoft/yii2/db/Schema.php:677)

0 /site/src/vendor/yiisoft/yii2/db/Command.php(1298): yii\db\Schema->convertException(Object(PDOException), 'SELECT types....')

1 /site/src/vendor/yiisoft/yii2/db/Command.php(1159): yii\db\Command->internalExecute('SELECT types....')

2 /site/src/vendor/yiisoft/yii2/db/Command.php(401): yii\db\Command->queryInternal('fetchAll', NULL)

3 /site/src/vendor/yiisoft/yii2/db/Query.php(248): yii\db\Command->queryAll()

4 /site/src/vendor/craftcms/cms/src/db/Query.php(152): yii\db\Query->all(NULL)

5 /site/src/vendor/spicyweb/craft-neo/src/Plugin.php(148): craft\db\Query->all()

6 [internal function]: benf\neo\Plugin->benf\neo{closure}(Object(craft\events\RebuildConfigEvent))

7 /site/src/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(craft\events\RebuildConfigEvent))

8 /site/src/vendor/yiisoft/yii2/base/Component.php(636): yii\base\Event::trigger('craft\services\...', 'rebuild', Object(craft\events\RebuildConfigEvent))

9 /site/src/vendor/craftcms/cms/src/services/ProjectConfig.php(1149): yii\base\Component->trigger('rebuild', Object(craft\events\RebuildConfigEvent))

10 /site/src/vendor/spicyweb/craft-fieldlabels/src/migrations/m200812_104254_craft_3_5_field_layout_transition_part_2.php(86): craft\services\ProjectConfig->rebuild()

11 /site/src/vendor/craftcms/cms/src/db/Migration.php(52): spicyweb\fieldlabels\migrations\m200812_104254_craft_3_5_field_layout_transition_part_2->safeUp()

12 /site/src/vendor/craftcms/cms/src/db/MigrationManager.php(232): craft\db\Migration->up(true)

13 /site/src/vendor/craftcms/cms/src/db/MigrationManager.php(148): craft\db\MigrationManager->migrateUp(Object(spicyweb\fieldlabels\migrations\m200812_104254_craft_3_5_field_layout_transition_part_2))

14 /site/src/vendor/craftcms/cms/src/services/Updates.php(227): craft\db\MigrationManager->up()

15 /site/src/vendor/craftcms/cms/src/controllers/BaseUpdaterController.php(509): craft\services\Updates->runMigrations(Array)

16 /site/src/vendor/craftcms/cms/src/controllers/UpdaterController.php(203): craft\controllers\BaseUpdaterController->runMigrations(Array, 'restore-db')

17 [internal function]: craft\controllers\UpdaterController->actionMigrate()

18 /site/src/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)

19 /site/src/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams(Array)

20 /site/src/vendor/craftcms/cms/src/web/Controller.php(181): yii\base\Controller->runAction('migrate', Array)

21 /site/src/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('migrate', Array)

22 /site/src/vendor/craftcms/cms/src/web/Application.php(294): yii\base\Module->runAction('updater/migrate', Array)

23 /site/src/vendor/craftcms/cms/src/web/Application.php(684): craft\web\Application->runAction('updater/migrate')

24 /site/src/vendor/craftcms/cms/src/web/Application.php(247): craft\web\Application->_processUpdateLogic(Object(craft\web\Request))

25 /site/src/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))

26 /site/src/public/index.php(21): yii\base\Application->run()

27 {main}

Other information

ttempleton commented 4 years ago

Turns out if Field Labels' migrations run first, then the resulting project config rebuild will cause Neo to try to access a maxSiblingBlocks column that doesn't exist yet. This should now be fixed in Neo 2.8.6, which now checks for the column's existence during the rebuild.