craftcms / cms

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

Database migration failing between 3.6.7 and 3.6.10 #7673

Closed Andrew-Delaney closed 3 years ago

Andrew-Delaney commented 3 years ago

Description

When updating our live site from CMS version 3.6.7 to 3.6.10 via Composer we're getting the following database migration error:

Database Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'craft_projectconfignames' already exists
The SQL being executed was: CREATE TABLE craft_projectconfignames (
uid char(36) NOT NULL DEFAULT '0',
name varchar(255) NOT NULL,
PRIMARY KEY(uid)
) ENGINE = InnoDb DEFAULT CHARACTER SET = utf8 DEFAULT COLLATE = utf8_unicode_ci

Migration: craft\migrations\m210224_162000_add_projectconfignames_table

Output:

> create table {{%projectconfignames}} ...Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'craft_projectconfignames' already exists
The SQL being executed was: CREATE TABLE craft_projectconfignames (
uid char(36) NOT NULL DEFAULT '0',
name varchar(255) NOT NULL,
PRIMARY KEY(uid)
) ENGINE = InnoDb DEFAULT CHARACTER SET = utf8 DEFAULT COLLATE = utf8_unicode_ci (/var/www/vendor/yiisoft/yii2/db/Schema.php:678)
#0 /var/www/vendor/yiisoft/yii2/db/Command.php(1304): yii\db\Schema->convertException(Object(PDOException), 'CREATE TABLE c...')
#1 /var/www/vendor/yiisoft/yii2/db/Command.php(1099): yii\db\Command->internalExecute('CREATE TABLE c...')
#2 /var/www/vendor/yiisoft/yii2/db/Migration.php(323): yii\db\Command->execute()
#3 /var/www/vendor/craftcms/cms/src/migrations/m210224_162000_add_projectconfignames_table.php(22): yii\db\Migration->createTable('{{%projectconfi...', Array)
#4 /var/www/vendor/craftcms/cms/src/db/Migration.php(52): craft\migrations\m210224_162000_add_projectconfignames_table->safeUp()
#5 /var/www/vendor/craftcms/cms/src/db/MigrationManager.php(232): craft\db\Migration->up(true)
#6 /var/www/vendor/craftcms/cms/src/db/MigrationManager.php(148): craft\db\MigrationManager->migrateUp(Object(craft\migrations\m210224_162000_add_projectconfignames_table))
#7 /var/www/vendor/craftcms/cms/src/services/Updates.php(250): craft\db\MigrationManager->up()
#8 /var/www/vendor/craftcms/cms/src/controllers/BaseUpdaterController.php(509): craft\services\Updates->runMigrations(Array)
#9 /var/www/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/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#12 /var/www/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#13 /var/www/vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction('migrate', Array)
#14 /var/www/vendor/yiisoft/yii2/base/Module.php(534): craft\web\Controller->runAction('migrate', Array)
#15 /var/www/vendor/craftcms/cms/src/web/Application.php(274): yii\base\Module->runAction('updater/migrate', Array)
#16 /var/www/vendor/craftcms/cms/src/web/Application.php(665): craft\web\Application->runAction('updater/migrate')
#17 /var/www/vendor/craftcms/cms/src/web/Application.php(212): craft\web\Application->_processUpdateLogic(Object(craft\web\Request))
#18 /var/www/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))
#19 /var/www/web/index.php(22): yii\base\Application->run()
#20 {main}

Additional info

brandonkelly commented 3 years ago

You must have run the update previously and unsuccessfully. I’ve just updated the m210224_162000_add_projectconfignames_table migration to be more defensive. In the meantime, manually delete your projectconfignames table and try updating again.