Cms: Upgrade to 3.2.0 fails during migration

Created on 11 Jul 2019  路  3Comments  路  Source: craftcms/cms

Description

I'm upgrading an install to 3.2 but it falls over at "migrate/all".

Steps to reproduce

  1. run ./craft update craft
  2. get error

Additional info

  • Craft version: 3.1.34 => 3.2.0
  • PHP version: 7.3.6
  • Database driver & version: MySQL 5.7.26
  • Plugins & versions: here's a screenshot

I've not had any luck finding a way around it. Here's the cli output which is a mystery to me:

Applying new migrations ... error: The command "'/project/craft' 'migrate/all' '--no-content'" failed.

Exit Code: 1(General error)

Working directory: /project

Output:
================
Yii Migration Tool (based on Yii v2.0.21)

    > create table {{%drafts}} ...Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'drafts' already exists
The SQL being executed was: CREATE TABLE `drafts` (
    `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `sourceId` int(11) NOT NULL,
    `revisionId` int(11) NOT NULL,
    `creatorId` int(11) NOT NULL,
    `name` varchar(255) NOT NULL,
    `notes` text
) ENGINE=InnoDb DEFAULT CHARSET=utf8 (/project/vendor/yiisoft/yii2/db/Schema.php:664)
#0 /project/vendor/yiisoft/yii2/db/Command.php(1295): yii\db\Schema->convertException(Object(PDOException), 'CREATE TABLE `d...')
#1 /project/vendor/yiisoft/yii2/db/Command.php(1091): yii\db\Command->internalExecute('CREATE TABLE `d...')
#2 /project/vendor/yiisoft/yii2/db/Migration.php(323): yii\db\Command->execute()
#3 /project/vendor/craftcms/cms/src/migrations/m190312_152740_element_revisions.php(27): yii\db\Migration->createTable('{{%drafts}}', Array)
#4 /project/vendor/craftcms/cms/src/db/Migration.php(56): craft\migrations\m190312_152740_element_revisions->safeUp()
#5 /project/vendor/craftcms/cms/src/db/MigrationManager.php(243): craft\db\Migration->up(true)
#6 /project/vendor/craftcms/cms/src/db/MigrationManager.php(163): craft\db\MigrationManager->migrateUp(Object(craft\migrations\m190312_152740_element_revisions))
#7 /project/vendor/craftcms/cms/src/services/Updates.php(217): craft\db\MigrationManager->up()
#8 /project/vendor/craftcms/cms/src/console/controllers/MigrateController.php(259): craft\services\Updates->runMigrations(Array)
#9 [internal function]: craft\console\controllers\MigrateController->actionAll()
#10 /project/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#11 /project/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#12 /project/vendor/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('all', Array)
#13 /project/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('all', Array)
#14 /project/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#15 /project/vendor/craftcms/cms/src/console/Application.php(93): yii\console\Application->runAction('migrate/all', Array)
#16 /project/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/all', Array)
#17 /project/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#18 /project/craft(22): yii\base\Application->run()
#19 {main}


Error Output:
================
Exception 'craft\errors\MigrateException' with message 'An error occurred while migrating Craft CMS.'

in /project/vendor/craftcms/cms/src/services/Updates.php:233

Stack trace:
#0 /project/vendor/craftcms/cms/src/console/controllers/MigrateController.php(259): craft\services\Updates->runMigrations(Array)
#1 [internal function]: craft\console\controllers\MigrateController->actionAll()
#2 /project/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#3 /project/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#4 /project/vendor/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('all', Array)
#5 /project/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('all', Array)
#6 /project/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#7 /project/vendor/craftcms/cms/src/console/Application.php(93): yii\console\Application->runAction('migrate/all', Array)
#8 /project/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/all', Array)
#9 /project/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#10 /project/craft(22): yii\base\Application->run()
#11 {main}


Output:

Yii Migration Tool (based on Yii v2.0.21)

    > create table {{%drafts}} ...Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'drafts' already exists
The SQL being executed was: CREATE TABLE `drafts` (
    `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `sourceId` int(11) NOT NULL,
    `revisionId` int(11) NOT NULL,
    `creatorId` int(11) NOT NULL,
    `name` varchar(255) NOT NULL,
    `notes` text
) ENGINE=InnoDb DEFAULT CHARSET=utf8 (/project/vendor/yiisoft/yii2/db/Schema.php:664)
#0 /project/vendor/yiisoft/yii2/db/Command.php(1295): yii\db\Schema->convertException(Object(PDOException), 'CREATE TABLE `d...')
#1 /project/vendor/yiisoft/yii2/db/Command.php(1091): yii\db\Command->internalExecute('CREATE TABLE `d...')
#2 /project/vendor/yiisoft/yii2/db/Migration.php(323): yii\db\Command->execute()
#3 /project/vendor/craftcms/cms/src/migrations/m190312_152740_element_revisions.php(27): yii\db\Migration->createTable('{{%drafts}}', Array)
#4 /project/vendor/craftcms/cms/src/db/Migration.php(56): craft\migrations\m190312_152740_element_revisions->safeUp()
#5 /project/vendor/craftcms/cms/src/db/MigrationManager.php(243): craft\db\Migration->up(true)
#6 /project/vendor/craftcms/cms/src/db/MigrationManager.php(163): craft\db\MigrationManager->migrateUp(Object(craft\migrations\m190312_152740_element_revisions))
#7 /project/vendor/craftcms/cms/src/services/Updates.php(217): craft\db\MigrationManager->up()
#8 /project/vendor/craftcms/cms/src/console/controllers/MigrateController.php(259): craft\services\Updates->runMigrations(Array)
#9 [internal function]: craft\console\controllers\MigrateController->actionAll()
#10 /project/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#11 /project/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#12 /project/vendor/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('all', Array)
#13 /project/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('all', Array)
#14 /project/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#15 /project/vendor/craftcms/cms/src/console/Application.php(93): yii\console\Application->runAction('migrate/all', Array)
#16 /project/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/all', Array)
#17 /project/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#18 /project/craft(22): yii\base\Application->run()
#19 {main}

Most helpful comment

The error you posted would happen if you were trying to update to Craft 3.2 on top of a database that had already been partially updated to Craft 3.2. Perhaps after it failed the first time, you restored a database backup and tried again; but restoring a database backup won鈥檛 delete any new tables that were added by the initial update attempt.

Try doing this to ensure you鈥檙e really starting fresh:

  1. Delete your database
  2. Recreate it
  3. Import your database backup
  4. Delete your config/project.yaml file (if you have one)
  5. Delete your storage/logs/ folder
  6. Reattempt the update

If it fails again, this time your storage/logs/ folder should contain the original error. Please post that, and its stack trace.

All 3 comments

The error you posted would happen if you were trying to update to Craft 3.2 on top of a database that had already been partially updated to Craft 3.2. Perhaps after it failed the first time, you restored a database backup and tried again; but restoring a database backup won鈥檛 delete any new tables that were added by the initial update attempt.

Try doing this to ensure you鈥檙e really starting fresh:

  1. Delete your database
  2. Recreate it
  3. Import your database backup
  4. Delete your config/project.yaml file (if you have one)
  5. Delete your storage/logs/ folder
  6. Reattempt the update

If it fails again, this time your storage/logs/ folder should contain the original error. Please post that, and its stack trace.

馃憤 Thanks, that does make sense. I'll give it a go tomorrow morning.

Just a clarifying, this error can show up if you import an old database into a craft instance that was already upgraded from the old database's Craft version, even if it wasn't a "partial" upgrade. If this is the case, you don't have to delete anything other than the existing tables in your database.

On FortRabbit, you don't have permissions to drop the entire database, and creating a new app is kind of a pain, but you can run the following SQL to drop all the tables in the database, so you don't have to create a whole new app:

Note: This will delete all the tables in your database, so use with caution, but I find it really helpful when building dev/staging sites and updating data from production.

SET FOREIGN_KEY_CHECKS = 0; 
SET @tables = NULL;
SET GROUP_CONCAT_MAX_LEN=32768;

SELECT GROUP_CONCAT('`', table_schema, '`.`', table_name, '`') INTO @tables
FROM   information_schema.tables
WHERE  table_schema = (SELECT DATABASE());
SELECT IFNULL(@tables, '') INTO @tables;

SET        @tables = CONCAT('DROP TABLE IF EXISTS ', @tables);
PREPARE    stmt FROM @tables;
EXECUTE    stmt;
DEALLOCATE PREPARE stmt;
SET        FOREIGN_KEY_CHECKS = 1;
Was this page helpful?
0 / 5 - 0 ratings