craftcms / cms

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

Missing `projectconfignames` table on 3.6.7 to 3.6.9 upgrade #7662

Closed shennyg closed 3 years ago

shennyg commented 3 years ago

Description

Upgrading from 3.6.7 to 3.6.9 doesn't create the required Table::PROJECTCONFIGNAMES / 'projectconfignames' table early enough.

It's failing here: https://github.com/craftcms/cms/commit/1dee096ba7b5cb277d3768ac41c174b211ea5858#diff-e39eae0845ed5714c6f2c936b244be3dfe3818075cc4b02f200edae0d0889cf3R1693-R1696 because this migration cannot be run: https://github.com/craftcms/cms/commit/1dee096ba7b5cb277d3768ac41c174b211ea5858#diff-92ced046c1bcc6b20dd555c2895b8224861305f8e396378c54ffb00f7efc9527

Steps to reproduce

  1. Run composer update on an existing Craft CMS 3.6.7 project.
  2. Run build commands per docs:
$ php craft migrate/all --no-content --interactive=0
Exception 'yii\base\Exception' with message 'Unable to write new project config files'

in /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/craftcms/cms/src/services/ProjectConfig.php:1732

Caused by: Exception 'yii\db\Exception' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'site_com.projectconfignames' doesn't exist
The SQL being executed was: SELECT `uid`, `name`
FROM `projectconfignames`'

in /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/db/Schema.php:678

Error Info:
Array
(
    [0] => 42S02
    [1] => 1146
    [2] => Table 'site_com.projectconfignames' doesn't exist
)

Caused by: Exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'site_com.projectconfignames' doesn't exist'

in /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/db/Command.php:1299

Stack trace:
#0 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/db/Command.php(1299): PDOStatement->execute()
#1 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/db/Command.php(1165): yii\db\Command->internalExecute()
#2 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/db/Command.php(407): yii\db\Command->queryInternal()
#3 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/craftcms/cms/src/db/Query.php(128): yii\db\Command->queryAll()
#4 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/craftcms/cms/src/services/ProjectConfig.php(1696): craft\db\Query->pairs()
#5 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/craftcms/cms/src/services/ProjectConfig.php(834): craft\services\ProjectConfig->_updateYamlFiles()
#6 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/craftcms/cms/src/services/ProjectConfig.php(544): craft\services\ProjectConfig->saveModifiedConfigData()
#7 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/craftcms/cms/src/console/controllers/MigrateController.php(232): craft\services\ProjectConfig->regenerateYamlFromConfig()
#8 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/base/Controller.php(179): craft\console\controllers\MigrateController->beforeAction()
#9 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/console/Controller.php(184): yii\base\Controller->runAction()
#10 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/base/Module.php(534): yii\console\Controller->runAction()
#11 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/console/Application.php(181): yii\base\Module->runAction()
#12 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/craftcms/cms/src/console/Application.php(89): yii\console\Application->runAction()
#13 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/console/Application.php(148): craft\console\Application->runAction()
#14 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/base/Application.php(392): yii\console\Application->handleRequest()
#15 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/craft(23): yii\base\Application->run()
$ php craft project-config/apply --force
Craft has pending migrations. Please run `craft migrate/all` first.
$ php craft migrate/all
# same error as above.
$ php craft migrate --track=content --interactive=0
# same error as above.

If you manually add the table:

CREATE TABLE `projectconfignames` (
        `uid` char(36) NOT NULL DEFAULT '0',
        `name` varchar(255) NOT NULL,
        PRIMARY KEY(`uid`)
) ENGINE = InnoDb DEFAULT CHARACTER SET = utf8

Migrate runs but fails:

$ php craft migrate/all
Yii Migration Tool (based on Yii v2.0.41.1)

Total 2 new Craft migrations to be applied:
    - m210223_150900_add_new_element_gql_schema_components
    - m210224_162000_add_projectconfignames_table

Apply the above migrations? (yes|no) [no]:yes
Backup the database? (yes|no) [no]:yes
Backing up the database ... done
*** applying m210223_150900_add_new_element_gql_schema_components
*** applied m210223_150900_add_new_element_gql_schema_components (time: 0.031s)

*** applying m210224_162000_add_projectconfignames_table
    > create table {{%projectconfignames}} ...Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'projectconfignames' already exists
The SQL being executed was: CREATE TABLE `projectconfignames` (
        `uid` char(36) NOT NULL DEFAULT '0',
        `name` varchar(255) NOT NULL,
        PRIMARY KEY(`uid`)
) ENGINE = InnoDb DEFAULT CHARACTER SET = utf8 (/home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/db/Schema.php:678)
#0 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/db/Command.php(1304): yii\db\Schema->convertException()
#1 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/db/Command.php(1099): yii\db\Command->internalExecute()
#2 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/db/Migration.php(323): yii\db\Command->execute()
#3 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/craftcms/cms/src/migrations/m210224_162000_add_projectconfignames_table.php(22): yii\db\Migration->createTable()
#4 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/craftcms/cms/src/db/Migration.php(52): craft\migrations\m210224_162000_add_projectconfignames_table->safeUp()
#5 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(744): craft\db\Migration->up()
#6 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/craftcms/cms/src/console/controllers/MigrateController.php(374): yii\console\controllers\BaseMigrateController->migrateUp()
#7 [internal function]: craft\console\controllers\MigrateController->actionAll()
#8 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#9 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams()
#10 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/console/Controller.php(184): yii\base\Controller->runAction()
#11 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/base/Module.php(534): yii\console\Controller->runAction()
#12 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/console/Application.php(181): yii\base\Module->runAction()
#13 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/craftcms/cms/src/console/Application.php(89): yii\console\Application->runAction()
#14 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/console/Application.php(148): craft\console\Application->runAction()
#15 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/vendor/yiisoft/yii2/base/Application.php(392): yii\console\Application->handleRequest()
#16 /home/forge/site-com/releases/f818e72d60936df3ed96508f44f100061f569da1/craft(23): yii\base\Application->run()
#17 {main}
*** failed to apply m210224_162000_add_projectconfignames_table (time: 0.004s)

1 from 2 migration was applied.

Migration failed. The rest of the migrations are canceled.

Additional info

lucashfreitas commented 3 years ago

Same issue here!

brandonkelly commented 3 years ago

Thanks for reporting this. Just fixed for the next release.

To get the fix early, change your craftcms/cms requirement in composer.json to "dev-develop as 3.6.9" and run composer update.

brandonkelly commented 3 years ago

Craft 3.6.10 is out now with a fix for this.

andymakkolli commented 3 years ago

I am still experiencing this issue when trying to upgrade from 3.6.1 to 3.7.0 (as it applies previous migrations in turn). No idea how to skip 3.6.9 and go straight to 3.6.10, if it is indeed fixed...

brandonkelly commented 3 years ago

@andymakkolli Yeah it resurfaced in 3.7.0, sorry about that.

We just released 3.7.1 with a fix (225f24e53c00635fd282ca565a6c83e7c59a401c). You’ll need to restore a database backup from before the 3.7 update, then composer-update to 3.7.1 and this time it should work.