When the container is upgraded in Rancher, the database migration occurs repeatedly, and then the error analysis is reported.
1. When the container is upgraded for the first time in Rancher, the database migration will be repeated, and then the error will be reported to the upgrade failure. as shown in Figure 1
*** applying m210106_122427_add_columns_to_task_table
> add column article_type_id integer NOT NULL DEFAULT 0 COMMENT '文章类型ID' AFTER `type` to table {{%task}} ...Exception: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'article_type_id'
The SQL being executed was: ALTER TABLE `cpa_task` ADD `article_type_id` int(11) NOT NULL DEFAULT 0 COMMENT '文章类型ID' AFTER `type` (/mcloud/www/ccp_api/vendor/yiisoft/yii2/db/Schema.php:678)
#0 /mcloud/www/ccp_api/vendor/yiisoft/yii2/db/Command.php(1304): yii\db\Schema->convertException(Object(PDOException), 'ALTER TABLE `cp...')
#1 /mcloud/www/ccp_api/vendor/yiisoft/yii2/db/Command.php(1099): yii\db\Command->internalExecute('ALTER TABLE `cp...')
#2 /mcloud/www/ccp_api/vendor/yiisoft/yii2/db/Migration.php(377): yii\db\Command->execute()
#3 /mcloud/www/ccp_api/console/migrations/m210106_122427_add_columns_to_task_table.php(15): yii\db\Migration->addColumn('{{%task}}', 'article_type_id', Object(yii\db\mysql\ColumnSchemaBuilder))
#4 /mcloud/www/ccp_api/vendor/yiisoft/yii2/db/Migration.php(114): m210106_122427_add_columns_to_task_table->safeUp()
#5 /mcloud/www/ccp_api/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(744): yii\db\Migration->up()
#6 /mcloud/www/ccp_api/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(202): yii\console\controllers\BaseMigrateController->migrateUp('m210106_122427_...')
#7 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#8 /mcloud/www/ccp_api/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /mcloud/www/ccp_api/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#10 /mcloud/www/ccp_api/vendor/yiisoft/yii2/console/Controller.php(184): yii\base\Controller->runAction('', Array)
#11 /mcloud/www/ccp_api/vendor/yiisoft/yii2/base/Module.php(534): yii\console\Controller->runAction('', Array)
#12 /mcloud/www/ccp_api/vendor/yiisoft/yii2/console/Application.php(181): yii\base\Module->runAction('migrate', Array)
#13 /mcloud/www/ccp_api/vendor/yiisoft/yii2/console/Application.php(148): yii\console\Application->runAction('migrate', Array)
#14 /mcloud/www/ccp_api/vendor/yiisoft/yii2/base/Application.php(392): yii\console\Application->handleRequest(Object(yii\console\Request))
#15 /mcloud/www/ccp_api/yii(23): yii\base\Application->run()
#16 {main}
*** failed to apply m210106_122427_add_columns_to_task_table (time: 0.006s)
2. It has been determined that the database structure has not been manually modified. Analyze the health check of the container. Periodically make requests to containers to detect their health status. By default, Readiness and Liveness use the same configuration parameters. For applications with longer initializations, the ready detection time needs to be increased. Preliminary analysis conclusion: Due to the long execution time of the database migration, the initialization time of the container is too long, resulting in the failure of the health check, and then the container is constantly started and run, and the database migration is repeatedly executed. Decide to increase the ready detection time. Start detection after running: 10 seconds -> 100 seconds. as shown in Figure 2
3. Still reporting errors during initial deployment: ReplicaSet “API-77DFCC7CFB” has timed out progressing.; Deployment does not have minimum available.. as shown in Figure 3
4. Check the logs, which is still a problem of repeated execution of database migration. Check the table structure and the records in the migration table in MySQL to determine the migration record: M210402_052030_ADD_Columns_to_channel_app_source_table It does not exist in the migration table, but the table structure in MySQL is already the result of the execution of this migration record. as shown in Figure 4
m210402_052030_add_columns_to_channel_app_source_table
*** applying m201105_020453_add_article_read_count_column_to_channel_app_task_table
> add column article_read_count integer NOT NULL DEFAULT 0 COMMENT '文章的阅读数' AFTER `have_pub_number` to table {{%channel_app_task}} ...Exception: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'article_read_count'
The SQL being executed was: ALTER TABLE `cpa_channel_app_task` ADD `article_read_count` int(11) NOT NULL DEFAULT 0 COMMENT '文章的阅读数' AFTER `have_pub_number` (/mcloud/www/ccp_api/vendor/yiisoft/yii2/db/Schema.php:678)
#0 /mcloud/www/ccp_api/vendor/yiisoft/yii2/db/Command.php(1304): yii\db\Schema->convertException(Object(PDOException), 'ALTER TABLE `cp...')
#1 /mcloud/www/ccp_api/vendor/yiisoft/yii2/db/Command.php(1099): yii\db\Command->internalExecute('ALTER TABLE `cp...')
#2 /mcloud/www/ccp_api/vendor/yiisoft/yii2/db/Migration.php(377): yii\db\Command->execute()
#3 /mcloud/www/ccp_api/console/migrations/m201105_020453_add_article_read_count_column_to_channel_app_task_table.php(15): yii\db\Migration->addColumn('{{%channel_app_...', 'article_read_co...', Object(yii\db\mysql\ColumnSchemaBuilder))
#4 /mcloud/www/ccp_api/vendor/yiisoft/yii2/db/Migration.php(114): m201105_020453_add_article_read_count_column_to_channel_app_task_table->safeUp()
#5 /mcloud/www/ccp_api/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(744): yii\db\Migration->up()
#6 /mcloud/www/ccp_api/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(202): yii\console\controllers\BaseMigrateController->migrateUp('m201105_020453_...')
#7 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#8 /mcloud/www/ccp_api/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /mcloud/www/ccp_api/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#10 /mcloud/www/ccp_api/vendor/yiisoft/yii2/console/Controller.php(184): yii\base\Controller->runAction('', Array)
#11 /mcloud/www/ccp_api/vendor/yiisoft/yii2/base/Module.php(534): yii\console\Controller->runAction('', Array)
#12 /mcloud/www/ccp_api/vendor/yiisoft/yii2/console/Application.php(181): yii\base\Module->runAction('migrate', Array)
#13 /mcloud/www/ccp_api/vendor/yiisoft/yii2/console/Application.php(148): yii\console\Application->runAction('migrate', Array)
#14 /mcloud/www/ccp_api/vendor/yiisoft/yii2/base/Application.php(392): yii\console\Application->handleRequest(Object(yii\console\Request))
#15 /mcloud/www/ccp_api/yii(23): yii\base\Application->run()
#16 {main}
*** failed to apply m201105_020453_add_article_read_count_column_to_channel_app_task_table (time: 0.006s)
0 from 27 migrations were applied.
Migration failed. The rest of the migrations are canceled.
5. How long does it run to start the detection. : 10 seconds -> 100 seconds. as shown in Figure 5




