craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

[3.7 beta] Upgrade migrations did not complete #8079

Closed nickdunn closed 3 years ago

nickdunn commented 3 years ago

Description

I get this when I perform the upgrade. If I restore the previous database I can recreate this each time.

php_1     | Total 7 new Craft migrations to be applied:
php_1     |     - m210302_212318_canonical_elements
php_1     |     - m210329_214847_field_column_suffixes
php_1     |     - m210405_231315_provisional_drafts
php_1     |     - m210602_111300_project_config_names_in_config
php_1     |     - m210611_233510_default_placement_settings
php_1     |     - m210613_145522_sortable_global_sets
php_1     |     - m210613_184103_announcements
php_1     | 
php_1     | Backing up the database ... done
php_1     | *** applying m210302_212318_canonical_elements
php_1     |     > add column canonicalId integer AFTER `id` to table {{%elements}} ... done (time: 0.742s)
php_1     |     > add column dateLastMerged datetime AFTER `dateUpdated` to table {{%elements}} ... done (time: 0.667s)
php_1     |     > add foreign key fk_sctbwfkeqsqeifileuctxvchvwtwcibtrzvc: {{%elements}} (canonicalId) references {{%elements}} (id) ... done (time: 0.735s)
php_1     |     > execute SQL: UPDATE {{%elements}} [[e]]
php_1     | INNER JOIN {{%drafts}} [[d]] ON [[d.id]] = [[e.draftId]]
php_1     | SET [[e.canonicalId]] = [[d.sourceId]] ... done (time: 0.023s)
php_1     |     > execute SQL: UPDATE {{%elements}} [[e]]
php_1     | INNER JOIN {{%revisions}} [[d]] ON [[d.id]] = [[e.revisionId]]
php_1     | SET [[e.canonicalId]] = [[d.sourceId]] ... done (time: 0.101s)
php_1     |     > execute SQL: UPDATE {{%elements}} [[e]]
php_1     | INNER JOIN {{%drafts}} [[d]] ON [[d.id]] = [[e.revisionId]]
php_1     | SET [[e.dateLastMerged]] = [[d.dateLastMerged]] ... done (time: 0.041s)
php_1     | *** applied m210302_212318_canonical_elements (time: 2.343s)
php_1     | 
php_1     | *** applying m210329_214847_field_column_suffixes
php_1     |     > add column columnSuffix char(8) AFTER `context` to table {{%fields}} ... done (time: 0.290s)
php_1     | *** applied m210329_214847_field_column_suffixes (time: 0.306s)
php_1     | 
php_1     | *** applying m210405_231315_provisional_drafts
php_1     |     > add column provisional boolean NOT NULL DEFAULT FALSE AFTER `creatorId` to table {{%drafts}} ... done (time: 0.098s)
php_1     |     > create index idx_ubhdppypyirdhiifeckpycyjfmmgvzqnekfp on {{%drafts}} (creatorId,provisional) ... done (time: 0.029s)
php_1     | *** applied m210405_231315_provisional_drafts (time: 0.139s)
php_1     | 
php_1     | *** applying m210602_111300_project_config_names_in_config
php_1     |     > dropping {{%projectconfignames}} if it exists ... done (time: 0.014s)
php_1     | *** applied m210602_111300_project_config_names_in_config (time: 2.048s)
php_1     | 
php_1     | *** applying m210611_233510_default_placement_settings
php_1     |     > add column defaultPlacement enum('beginning','end') NOT NULL DEFAULT 'end' AFTER `handle` to table {{%categorygroups}} ... done (time: 0.075s)
php_1     |     > add column defaultPlacement enum('beginning','end') NOT NULL DEFAULT 'end' AFTER `propagationMethod` to table {{%sections}} ... done (time: 0.082s)
php_1     | *** applied m210611_233510_default_placement_settings (time: 0.170s)
php_1     | 
php_1     | *** applying m210613_145522_sortable_global_sets
php_1     |     > add column sortOrder smallint UNSIGNED AFTER `fieldLayoutId` to table {{%globalsets}} ... done (time: 0.074s)
php_1     |     > create index idx_bjmwbfqmovjpbwotismdfjgfprnuyjiqkhxb on {{%globalsets}} (sortOrder) ... done (time: 0.016s)
php_1     | Exception: Undefined index: name (/var/www/craft/vendor/craftcms/cms/src/services/Globals.php:335)
php_1     | #0 /var/www/craft/vendor/craftcms/cms/src/services/Globals.php(335): yii\base\ErrorHandler->handleError(8, 'Undefined index...', '/var/www/craft/...', 335, Array)
php_1     | #1 /var/www/craft/vendor/craftcms/cms/src/base/ApplicationTrait.php(1668): craft\services\Globals->handleChangedGlobalSet(Object(craft\events\ConfigEvent))
php_1     | #2 /var/www/craft/vendor/craftcms/cms/src/services/ProjectConfig.php(1189): craft\console\Application->craft\base\{closure}(Object(craft\events\ConfigEvent))
php_1     | #3 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
php_1     | #4 /var/www/craft/vendor/yiisoft/yii2/base/Component.php(628): call_user_func(Array, Object(craft\events\ConfigEvent))
php_1     | #5 /var/www/craft/vendor/craftcms/cms/src/services/ProjectConfig.php(749): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
php_1     | #6 /var/www/craft/vendor/craftcms/cms/src/services/ProjectConfig.php(1179): craft\services\ProjectConfig->_processConfigChangesInternal('globalSets.1dcd...')
php_1     | #7 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
php_1     | #8 /var/www/craft/vendor/yiisoft/yii2/base/Component.php(628): call_user_func(Array, Object(craft\events\ConfigEvent))
php_1     | #9 /var/www/craft/vendor/craftcms/cms/src/services/ProjectConfig.php(749): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
php_1     | #10 /var/www/craft/vendor/craftcms/cms/src/services/ProjectConfig.php(521): craft\services\ProjectConfig->_processConfigChangesInternal('globalSets.1dcd...', true, NULL)
php_1     | #11 /var/www/craft/vendor/craftcms/cms/src/migrations/m210613_145522_sortable_global_sets.php(39): craft\services\ProjectConfig->set('globalSets.1dcd...', 2)
php_1     | #12 /var/www/craft/vendor/craftcms/cms/src/db/Migration.php(52): craft\migrations\m210613_145522_sortable_global_sets->safeUp()
php_1     | #13 /var/www/craft/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(744): craft\db\Migration->up()
php_1     | #14 /var/www/craft/vendor/craftcms/cms/src/console/controllers/MigrateController.php(379): yii\console\controllers\BaseMigrateController->migrateUp('m210613_145522_...')
php_1     | #15 [internal function]: craft\console\controllers\MigrateController->actionAll()
php_1     | #16 /var/www/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
php_1     | #17 /var/www/craft/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
php_1     | #18 /var/www/craft/vendor/yiisoft/yii2/console/Controller.php(184): yii\base\Controller->runAction('all', Array)
php_1     | #19 /var/www/craft/vendor/yiisoft/yii2/base/Module.php(534): yii\console\Controller->runAction('all', Array)
php_1     | #20 /var/www/craft/vendor/yiisoft/yii2/console/Application.php(181): yii\base\Module->runAction('migrate/all', Array)
php_1     | #21 /var/www/craft/vendor/craftcms/cms/src/console/Application.php(89): yii\console\Application->runAction('migrate/all', Array)
php_1     | #22 /var/www/craft/vendor/yiisoft/yii2/console/Application.php(148): craft\console\Application->runAction('migrate/all', Array)
php_1     | #23 /var/www/craft/vendor/yiisoft/yii2/base/Application.php(392): yii\console\Application->handleRequest(Object(craft\console\Request))
php_1     | #24 /var/www/craft/craft(23): yii\base\Application->run()
php_1     | #25 {main}
php_1     | *** failed to apply m210613_145522_sortable_global_sets (time: 1.094s)
php_1     | 
php_1     | 
php_1     | 5 from 7 migrations were applied.
php_1     | 
php_1     | Migration failed. The rest of the migrations are canceled.

In the CP it then tells me:

To complete the update, some changes must be made to your database.

So I hit "Finish up" which yields:

Database Exception: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'sortOrder'
The SQL being executed was: ALTER TABLE globalsets ADD sortOrder smallint(6) UNSIGNED AFTER fieldLayoutId

Migration: craft\migrations\m210613_145522_sortable_global_sets

Output:

> add column sortOrder smallint UNSIGNED AFTER fieldLayoutId to table {{%globalsets}} ...Exception: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'sortOrder'
The SQL being executed was: ALTER TABLE globalsets ADD sortOrder smallint(6) UNSIGNED AFTER fieldLayoutId (/var/www/craft/vendor/yiisoft/yii2/db/Schema.php:678)
#0 /var/www/craft/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'ALTER TABLE gl...')
#1 /var/www/craft/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute('ALTER TABLE gl...')
#2 /var/www/craft/vendor/yiisoft/yii2/db/Migration.php(377): yii\db\Command->execute()
#3 /var/www/craft/vendor/craftcms/cms/src/migrations/m210613_145522_sortable_global_sets.php(22): yii\db\Migration->addColumn('{{%globalsets}}', 'sortOrder', Object(craft\db\mysql\ColumnSchemaBuilder))
#4 /var/www/craft/vendor/craftcms/cms/src/db/Migration.php(52): craft\migrations\m210613_145522_sortable_global_sets->safeUp()
#5 /var/www/craft/vendor/craftcms/cms/src/db/MigrationManager.php(232): craft\db\Migration->up(true)
#6 /var/www/craft/vendor/craftcms/cms/src/db/MigrationManager.php(148): craft\db\MigrationManager->migrateUp(Object(craft\migrations\m210613_145522_sortable_global_sets))
#7 /var/www/craft/vendor/craftcms/cms/src/services/Updates.php(250): craft\db\MigrationManager->up()
#8 /var/www/craft/vendor/craftcms/cms/src/controllers/BaseUpdaterController.php(509): craft\services\Updates->runMigrations(Array)
#9 /var/www/craft/vendor/craftcms/cms/src/controllers/UpdaterController.php(203): craft\controllers\BaseUpdaterController->runMigrations(Array, 'restore-db')
#10 [internal function]: craft\controllers\UpdaterController->actionMigrate()
#11 /var/www/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#12 /var/www/craft/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#13 /var/www/craft/vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction('migrate', Array)
#14 /var/www/craft/vendor/yiisoft/yii2/base/Module.php(534): craft\web\Controller->runAction('migrate', Array)
#15 /var/www/craft/vendor/craftcms/cms/src/web/Application.php(271): yii\base\Module->runAction('updater/migrate', Array)
#16 /var/www/craft/vendor/craftcms/cms/src/web/Application.php(662): craft\web\Application->runAction('updater/migrate')
#17 /var/www/craft/vendor/craftcms/cms/src/web/Application.php(208): craft\web\Application->_processUpdateLogic(Object(craft\web\Request))
#18 /var/www/craft/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))
#19 /var/www/craft/web/index.php(22): yii\base\Application->run()
#20 {main}

Additional info

brandonkelly commented 3 years ago

Here’s the original error you got:

Exception: Undefined index: name (/var/www/craft/vendor/craftcms/cms/src/services/Globals.php:335)

Here’s that line:

https://github.com/craftcms/cms/blob/7988b0508ef3b2c34d08a8fdee87a4504928b7e3/src/services/Globals.php#L335

So it’s saying you have a global set without a name which… shouldn’t be possible? Can you take a look at your global sets and see if that’s the case?

brandonkelly commented 3 years ago

I found a way to reproduce this, if there were any soft-deleted global sets. Just fixed it for the next release.

brandonkelly commented 3 years ago

3.7.0-beta.3 is out now with that fix.

nickdunn commented 3 years ago

Tried again with 3.7.0-beta.3 and it's all good, thanks!

brandonkelly commented 3 years ago

Thanks for checking!

elfacht commented 3 years ago

I got this issue whil upgrading from 3.6.17 to 3.7.0 (non-beta)


> add column sortOrder smallint UNSIGNED AFTER `fieldLayoutId` to table {{%globalsets}} ...Exception: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'sortOrder'
The SQL being executed was: ALTER TABLE `hcm_globalsets` ADD `sortOrder` smallint(6) UNSIGNED AFTER `fieldLayoutId` (/app/app/vendor/yiisoft/yii2/db/Schema.php:678)
#0 /app/app/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'ALTER TABLE `hc...')
#1 /app/app/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute('ALTER TABLE `hc...')
#2 /app/app/vendor/yiisoft/yii2/db/Migration.php(377): yii\db\Command->execute()
#3 /app/app/vendor/craftcms/cms/src/migrations/m210613_145522_sortable_global_sets.php(23): yii\db\Migration->addColumn('{{%globalsets}}', 'sortOrder', Object(craft\db\mysql\ColumnSchemaBuilder))
#4 /app/app/vendor/craftcms/cms/src/db/Migration.php(52): craft\migrations\m210613_145522_sortable_global_sets->safeUp()
#5 /app/app/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(744): craft\db\Migration->up()
#6 /app/app/vendor/craftcms/cms/src/console/controllers/MigrateController.php(379): yii\console\controllers\BaseMigrateController->migrateUp('m210613_145522_...')
#7 [internal function]: craft\console\controllers\MigrateController->actionAll()
#8 /app/app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /app/app/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#10 /app/app/vendor/yiisoft/yii2/console/Controller.php(184): yii\base\Controller->runAction('all', Array)
#11 /app/app/vendor/yiisoft/yii2/base/Module.php(534): yii\console\Controller->runAction('all', Array)
#12 /app/app/vendor/yiisoft/yii2/console/Application.php(181): yii\base\Module->runAction('migrate/all', Array)
#13 /app/app/vendor/craftcms/cms/src/console/Application.php(89): yii\console\Application->runAction('migrate/all', Array)
#14 /app/app/vendor/yiisoft/yii2/console/Application.php(148): craft\console\Application->runAction('migrate/all', Array)
#15 /app/app/vendor/yiisoft/yii2/base/Application.php(392): yii\console\Application->handleRequest(Object(craft\console\Request))
#16 /app/app/craft(22): yii\base\Application->run()
#17 {main}
*** failed to apply m210613_145522_sortable_global_sets (time: 0.037s)```

Any idea how to fix it?
brandonkelly commented 3 years ago

@elfacht Those “Column already exists” errors typically occur when you attempt to update once, it fails for some reason, and then you re-attempt the update without restoring a database backup first.

Please do the following:

  1. Restore a database backup from before your initial 3.7 update attempt.
  2. Make sure you’re running the latest 3.7 release (currently that’s 3.7.7), as other migration bugs have been fixed since 3.7.0. (You can see which version you’re currently running by searching your composer.lock file for "name": "craftcms/cms".)
  3. Try running the migrations again.
elfacht commented 3 years ago

@brandonkelly Tried it, still got the error.

elfacht commented 3 years ago

@brandonkelly I even tried an older backup (3.6.12 => 3.7.7) and still got this.

brandonkelly commented 3 years ago

@elfacht In that case can you please send your 3.6.12 database backup plus your composer.json + composer.lock files, over to support@craftcms.com? We can look into it from there.

elfacht commented 3 years ago

@brandonkelly Done. I sent you the 3.6.17 files since this is the production version. If you need the 3.6.12 just say so and I'll send it, too.