Update to 4.1.1 failed

Your software
My PHP version is : 7.4
My MySQL version is: 5.7.3

Updating/Installing Errors
I am (delete as applicable): Updating
Upgrading/installing via (delete as applicable) : Command Line

These errors are showing in the installer :

$ php74 console mautic:update:apply
Are you sure you wish to update Mautic to the latest version? y
Step    5 [--->------------------------] Removing deleted files

<warning>IMPORTANT: Run the same command again with --finish. For example 'php bin/console mautic:update:apply --finish'</warning>

$ php74 console mautic:update:apply --finish
Step    2 [->--------------------------] Migrating database schema...

An error occurred while updating the database. Check log for more details.

These errors are showing in the Mautic log :

 cat var/logs/mautic_prod-2021-12-26.php 
[2021-12-26 18:49:48] mautic.WARNING: Received SES webhook of type '' but couldn't understand payload [] []
[2021-12-26 19:46:23] mautic.WARNING: Received SES webhook of type '' but couldn't understand payload [] []
[2021-12-26 20:55:03] mautic.WARNING: Received SES webhook of type '' but couldn't understand payload [] []
[2021-12-26 21:03:03] mautic.WARNING: Received SES webhook of type '' but couldn't understand payload [] []
[2021-12-26 22:10:34] mautic.NOTICE: Doctrine\DBAL\Exception\TableExistsException: An exception occurred while executing '             CREATE TABLE mautic4campaign_summary (                 id INT UNSIGNED AUTO_INCREMENT NOT NULL,                 campaign_id INT UNSIGNED DEFAULT NULL,                 event_id INT UNSIGNED NOT NULL,                 date_triggered DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime_immutable)',                 scheduled_count INT NOT NULL,                 triggered_count INT NOT NULL,                 non_action_path_taken_count INT NOT NULL,                 failed_count INT NOT NULL,                 log_counts_processed INT,                 INDEX IDX_E7708E49F639F774 (campaign_id),                 INDEX IDX_E7708E4971F7E88B (event_id),                 UNIQUE INDEX campaign_event_date_triggered (campaign_id, event_id, date_triggered),                 PRIMARY KEY(id)             ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;         ':  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'mautic4campaign_summary' already exists (uncaught exception) at /www/htdocs/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 57 while running console command `doctrine:migrations:migrate` [] []
[2021-12-26 22:10:34] mautic.WARNING: Command `doctrine:migrations:migrate` exited with status code 1 [] []
[2021-12-26 22:10:34] mautic.WARNING: Command `mautic:update:apply` exited with status code 1 [] []

migration error

$ php74 ./mautic/bin/console doctrine:migrations:migrate
                                                         
                    Mautic Migrations                    
                                                         

WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)y
Migrating up to 20210623071326 from 20201105120328

  ++ migrating 20201120122846

     -> 
            CREATE TABLE mautic4campaign_summary (
                id INT UNSIGNED AUTO_INCREMENT NOT NULL,
                campaign_id INT UNSIGNED DEFAULT NULL,
                event_id INT UNSIGNED NOT NULL,
                date_triggered DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime_immutable)',
                scheduled_count INT NOT NULL,
                triggered_count INT NOT NULL,
                non_action_path_taken_count INT NOT NULL,
                failed_count INT NOT NULL,
                log_counts_processed INT,
                INDEX IDX_E7708E49F639F774 (campaign_id),
                INDEX IDX_E7708E4971F7E88B (event_id),
                UNIQUE INDEX campaign_event_date_triggered (campaign_id, event_id, date_triggered),
                PRIMARY KEY(id)
            ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;
Migration 20201120122846 failed during Execution. Error An exception occurred while executing '
            CREATE TABLE mautic4campaign_summary (
                id INT UNSIGNED AUTO_INCREMENT NOT NULL,
                campaign_id INT UNSIGNED DEFAULT NULL,
                event_id INT UNSIGNED NOT NULL,
                date_triggered DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime_immutable)',
                scheduled_count INT NOT NULL,
                triggered_count INT NOT NULL,
                non_action_path_taken_count INT NOT NULL,
                failed_count INT NOT NULL,
                log_counts_processed INT,
                INDEX IDX_E7708E49F639F774 (campaign_id),
                INDEX IDX_E7708E4971F7E88B (event_id),
                UNIQUE INDEX campaign_event_date_triggered (campaign_id, event_id, date_triggered),
                PRIMARY KEY(id)
            ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;
        ':

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'mautic4campaign_summary' already exists

In AbstractMySQLDriver.php line 57:
                                                                                                                  
  An exception occurred while executing '                                                                         
              CREATE TABLE mautic4campaign_summary (                                                              
                  id INT UNSIGNED AUTO_INCREMENT NOT NULL,                                                        
                  campaign_id INT UNSIGNED DEFAULT NULL,                                                          
                  event_id INT UNSIGNED NOT NULL,                                                                 
                  date_triggered DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime_immutable)',                    
                  scheduled_count INT NOT NULL,                                                                   
                  triggered_count INT NOT NULL,                                                                   
                  non_action_path_taken_count INT NOT NULL,                                                       
                  failed_count INT NOT NULL,                                                                      
                  log_counts_processed INT,                                                                       
                  INDEX IDX_E7708E49F639F774 (campaign_id),                                                       
                  INDEX IDX_E7708E4971F7E88B (event_id),                                                          
                  UNIQUE INDEX campaign_event_date_triggered (campaign_id, event_id, date_triggered),             
                  PRIMARY KEY(id)                                                                                 
              ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;  
          ':                                                                                                      
                                                                                                                  
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'mautic4campaign_summary' already exists         
                                                                                                                  

In Exception.php line 18:
                                                                                                           
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'mautic4campaign_summary' already exists  
                                                                                                           

In PDOConnection.php line 132:
                                                                                                           
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'mautic4campaign_summary' already exists

Your problem
My problem is :
I installed Mautic a couple of days ago. I got the notification that an update was published. I tried to update via the CLI and got the above error.
I guess, the database migration fails/failed.

I don’t know if that is a problem or if it can be ignored, because I installed 4.1.0 and therefore the migration isn’t necessary.

Web backend seems to run fine, but I don’t know whether I’m running in some problems in the future.

Regards

I fixed it myself now by dropping/deleting the mautic4campaign_summary table manually via PHPMyAdmin.

Nevertheless, I think the SQL in that migration should be CREATE TABLE IF NOT EXISTS mautic4campaign_summary [...]. This would prevent this error when the table is (for some reason) already existent.

I don’t know why the table existed, already, in the first place. I guess the production zip I used for installing added it to the database, but didn’t mark the migration as applied :man_shrugging:

The failing migration would have prevented applying the rest of 10 outstanding migrations. Therefore, all futures migrations would have failed and prevented a proper update.

Hopefully this helps others.

PS: Check if the table is empty before dropping it. Mine was. And create a backup before doing it.