I'm upgrading an install to 3.2 but it falls over at "migrate/all".
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}
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:
config/project.yaml file (if you have one)storage/logs/ folderIf 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;
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:
config/project.yamlfile (if you have one)storage/logs/folderIf it fails again, this time your
storage/logs/folder should contain the original error. Please post that, and its stack trace.