# Error during upgrade from 4.1.1 to 4.1.2

**URL:** <https://forum.mautic.org/t/error-during-upgrade-from-4-1-1-to-4-1-2/22576>\
**Category:** Mautic 4 Install/Upgrade Support\
**Created:** [February 3, 2022, 8:13am UTC](https://forum.mautic.org/t/error-during-upgrade-from-4-1-1-to-4-1-2/22576 "2022-02-03T08:13:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![castellino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/castellino/32/526_2.png) [@castellino](https://forum.mautic.org/u/castellino)\
**Post date:** [February 3, 2022, 8:13am UTC](https://forum.mautic.org/t/error-during-upgrade-from-4-1-1-to-4-1-2/22576/1 "2022-02-03T08:13:36Z")

</div>

**Your software**  
_My PHP version is_ : 7.4.27  
_My MySQL/MariaDB version is_: MySQL version (MySQL Community Server 8.0.28)

**Updating/Installing Errors**  
_I am_: Updating  
_Upgrading via_: Command Line

_These errors are showing in the installer_ :  
Generic error message

_These errors are showing in the Mautic log_ :

[2022-02-02 18:02:10] console.CRITICAL: Error thrown while running command “doctrine:migrations:migrate --quiet --no-interaction”. Message: “An exception occurred while executing ’ CREATE TABLE mt\_campaign\_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\_42D3FE64F639F774 (campaign\_id), INDEX IDX\_42D3FE6471F7E88B (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 ‘mt\_campaign\_summary’ already exists” {“exception”:"[object] (Doctrine\DBAL\Exception\TableExistsException(code: 0): An exception occurred while executing '\n CREATE TABLE mt\_campaign\_summary (\n id INT UNSIGNED AUTO\_INCREMENT NOT NULL,\n campaign\_id INT UNSIGNED DEFAULT NULL,\n event\_id INT UNSIGNED NOT NULL,\n date\_triggered DATETIME DEFAULT NULL COMMENT ‘(DC2Type:datetime\_immutable)’,\n scheduled\_count INT NOT NULL,\n triggered\_count INT NOT NULL,\n non\_action\_path\_taken\_count INT NOT NULL,\n failed\_count INT NOT NULL,\n log\_counts\_processed INT,\n INDEX IDX\_42D3FE64F639F774 (campaign\_id),\n INDEX IDX\_42D3FE6471F7E88B (event\_id),\n UNIQUE INDEX campaign\_event\_date\_triggered (campaign\_id, event\_id, date\_triggered),\n PRIMARY KEY(id)\n ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW\_FORMAT = DYNAMIC;\n ':\n\nSQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘mt\_campaign\_summary’ already exists at /var/www/castellino/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:57, Doctrine\DBAL\Driver\PDO\Exception(code: 42S01): SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘mt\_campaign\_summary’ already exists at /var/www/castellino/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18, PDOException(code: 42S01): SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘mt\_campaign\_summary’ already exists at /var/www/castellino/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:132)",“command”:“doctrine:migrations:migrate --quiet --no-interaction”,“message”:“An exception occurred while executing '\n CREATE TABLE mt\_campaign\_summary (\n id INT UNSIGNED AUTO\_INCREMENT NOT NULL,\n campaign\_id INT UNSIGNED DEFAULT NULL,\n event\_id INT UNSIGNED NOT NULL,\n date\_triggered DATETIME DEFAULT NULL COMMENT ‘(DC2Type:datetime\_immutable)’,\n scheduled\_count INT NOT NULL,\n triggered\_count INT NOT NULL,\n non\_action\_path\_taken\_count INT NOT NULL,\n failed\_count INT NOT NULL,\n log\_counts\_processed INT,\n INDEX IDX\_42D3FE64F639F774 (campaign\_id),\n INDEX IDX\_42D3FE6471F7E88B (event\_id),\n UNIQUE INDEX campaign\_event\_date\_triggered (campaign\_id, event\_id, date\_triggered),\n PRIMARY KEY(id)\n ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW\_FORMAT = DYNAMIC;\n ':\n\nSQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘mt\_campaign\_summary’ already exists”}

**Your problem**  
_My problem is_ :

Upgrading from a newly installed version 4.1.1 to version 4.1.2 results in an error while updating the database.  
In the log file you can see that it tries to create the table mt\_campaign\_summary  
This table is already present, so I think it shouldn’t be a CREATE TABLE but an ALTER TABLE

_Steps I have tried to fix the problem_ :

Since the current installation is new, and not having created campaigns yet, I could delete the table before starting the procedure, but I doubt that this is the correct procedure

---

<div class="post-metadata">

**Author:** ![castellino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/castellino/32/526_2.png) [@castellino](https://forum.mautic.org/u/castellino)\
**Post date:** [February 8, 2022, 3:51pm UTC](https://forum.mautic.org/t/error-during-upgrade-from-4-1-1-to-4-1-2/22576/2 "2022-02-08T15:51:46Z")

</div>

The problem appears to be in the file Version20201120122846.php  
Here is the creation of table mt\_campaign\_summary  
If you comment the creation of this table, the update end with success.  
I checked the sql to create mt\_campaign\_summary and the table is the same as in the previous version (4.1.1).  
For this reason I assume that the file Version20201120122846.php should not be included in the migrations to upgrade from 4.1.1 to 4.1.2

---

<div class="post-metadata">

**Author:** ![raramuridesign](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/raramuridesign/32/13226_2.png) [@raramuridesign](https://forum.mautic.org/u/raramuridesign)\
**Post date:** [February 10, 2022, 4:23pm UTC](https://forum.mautic.org/t/error-during-upgrade-from-4-1-1-to-4-1-2/22576/3 "2022-02-10T16:23:47Z")

</div>

@castellino I think you should submit a github issue on this, as it does look like an issue  
@silavapi

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [March 7, 2022, 10:52am UTC](https://forum.mautic.org/t/error-during-upgrade-from-4-1-1-to-4-1-2/22576/4 "2022-03-07T10:52:09Z")

</div>

Issue and PRs already exist 🙂

Please see these PRs:

> <https://github.com/mautic/mautic/pull/10878>
>
> Fix #10877: The logic to check if the table exists and if it has foreign keys is… weak and causes issues when foreign keys have different names (as it frequently happens).
> 
> \<!-- ## Which branch should I use for my PR?
> 
> Assuming that:
> 
> a = current major release
> b = current minor release
> c = future major release
> 
> \* a.x for any features and enhancements (e.g. 4.x)
> \* a.b for any bug fixes (e.g. 4.0, 4.1, 4.2)
> \* c.x for any features, enhancements or bug fixes with backward compatibility breaking changes (e.g. 5.x) --\>
> 
> | Q | A
> | -------------------------------------- | ---
> | Bug fix? (use the a.b branch) | 4.1
> | New feature/enhancement? (use the a.x branch) | No
> | Deprecations? | \[No
> | BC breaks? (use the c.x branch) | \[No
> | Automated tests included? | No
> | Related user documentation PR URL |
> | Related developer documentation PR URL | 
> | Issue(s) addressed | Fixes #10877, #10870, #10865, #9129
> 
> \<!--
> Additionally (see https://contribute.mautic.org/contributing-to-mautic/developer/code/pull-requests#work-on-your-pull-request):
> - Always add tests and ensure they pass.
> - Bug fixes must be submitted against the lowest maintained branch where they apply
> (lowest branches are regularly merged to upper ones so they get the fixes too.)
> - Features and deprecations must be submitted against the "4.x" branch.
> \--\>
> 
> \#### Description:
> 
> The problem comes from the foreign keys: the migration assumes the names of the foreign keys are deterministic, but they aren't, and this causes the issue.
> 
> The check, in fact, groups the creation of the table and the creation of the foreign keys in one condition, but this is wrong, as maybe the table is there and the names of foreign keys are different than the ones generated by the migration: if names are different (and they are different), then the migration fail.
> 
> The refactored logic is now more solid and avoids issues running the migration, applying only the queries really necessary.
> 
> More details here: https://github.com/mautic/mautic/issues/9129#issuecomment-1044958793
> 
> \#### Steps to test this PR:
> 
> This is not always testable: it works only if you updated the database schema using \`bin/console doctrine:schema:update --force\`.
> 
> This command, in fact, creates the foreign keys with "arbitrary" names: in a case like this, the new logic can handle anyway the checks to verify if foreign keys already exist and, if they exist, skip the query to create them.
> 
> 1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs \[here\](https://contribute.mautic.org/contributing-to-mautic/tester))
> 2.
> 
> 
> \<a href="https://gitpod.io/#https://github.com/mautic/mautic/pull/10878"\>\<img src="https://gitpod.io/button/open-in-gitpod.svg"/\>\</a\>

> <https://github.com/mautic/mautic/pull/10931>
>
> \<!-- ## Which branch should I use for my PR?
> 
> Assuming that:
> 
> a = current ma…jor release
> b = current minor release
> c = future major release
> 
> \* a.x for any features and enhancements (e.g. 4.x)
> \* a.b for any bug fixes (e.g. 4.0, 4.1, 4.2)
> \* c.x for any features, enhancements or bug fixes with backward compatibility breaking changes (e.g. 5.x) --\>
> 
> | Q | A
> | -------------------------------------- | ---
> | Bug fix? (use the a.b branch) | \[x\]
> | New feature/enhancement? (use the a.x branch) | \[\]
> | Deprecations? | \[\]
> | BC breaks? (use the c.x branch) | \[\]
> | Automated tests included? | \[\] 
> | Related user documentation PR URL | mautic/mautic-documentation#... 
> | Related developer documentation PR URL | mautic/developer-documentation#... 
> | Issue(s) addressed | Fixes https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/13
> 
> \<!--
> Additionally (see https://contribute.mautic.org/contributing-to-mautic/developer/code/pull-requests#work-on-your-pull-request):
> - Always add tests and ensure they pass.
> - Bug fixes must be submitted against the lowest maintained branch where they apply
> (lowest branches are regularly merged to upper ones so they get the fixes too.)
> - Features and deprecations must be submitted against the "4.x" branch.
> \--\>
> 
> \#### Description:
> 
> There are 2 problematic migrations:
> 
> \`\`\`sql
> Table ‘\[prefix\]campaign\_summary’ already exists
> \`\`\`
> 
> The summary table check was generating the foreign key names with double-prefixed table. So if the table prefix was \`m\_\` then it was generating the name of \`m\_m\_campaign\_summrary\`. So the migration was checking for different FK names then it was later creating.
> 
> \`\`\`sql
> An exception occurred while executing 'ALTER TABLE \`\[prefix\]lead\_event\_log\` RENAME  
> INDEX \`IDX\_SEARCH\` TO \`\[prefix\]IDX\_SEARCH\`'
> \`\`\`
> 
> The renaming of the INDEX\_SEARCH on the lead\_event\_log table had similar issue with table prefix. I fortified the check.
> 
> \#### Steps to test this PR:
> 
> This will be hard to test on GitPod.
> 
> 1. Create fresh Mautic installation from version 4.2 with a table prefix set
> 2. Run \`bin/console mautic:migrations:migrate\`
> 
> 
> \<a href="https://gitpod.io/#https://github.com/mautic/mautic/pull/10931"\>\<img src="https://gitpod.io/button/open-in-gitpod.svg"/\>\</a\>
