# MySQL error upgrading to 4.2

**URL:** <https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867>\
**Category:** Mautic 4 Install/Upgrade Support\
**Created:** [March 1, 2022, 5:29pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867 "2022-03-01T17:29:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwmarketing](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/cwmarketing/32/2567_2.png) [@cwmarketing](https://forum.mautic.org/u/cwmarketing)\
**Post date:** [March 1, 2022, 5:29pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/1 "2022-03-01T17:29:15Z")

</div>

**Your software**  
_My PHP version is_ : 7.4  
_My MySQL/MariaDB version is_ (delete as applicable): Ver 15.1 Distrib 10.3.32-MariaDB

**Updating/Installing Errors**  
_I am_ (delete as applicable): Updating  
_Upgrading/installing via_ (delete as applicable) : Command line

_These errors are showing in the installer_ :  
`An error occurred while updating the database. Check log for more details.`

_These errors are showing in the Mautic log_ :  
` mautic.NOTICE: Doctrine\DBAL\Exception\SyntaxErrorException: An exception occurred while executing 'ALTER TABLE `ma_lead_event_log` RENAME INDEX `IDX_SEARCH` TO `ma_IDX_SEARCH`': SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds`

**Your problem**  
_My problem is_ :  
Trying to upgrade to 4.2

Attempting to upgrade to version 4.2 and it is unable to complete the process.

**What I’ve tried**  
When I run `php bin/console mautic:update:apply --finish` I get the error above.

Also - when I check the migrations with `php bin/console doctrine:migrations:status` I see that I appear to be far behind in migrations, considering there’s been a few updates since the last migration is listed and it says there are 10 migrations available:

![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/b/babd1839ae59660c8898af021c99e9bc83c3eccc.png)

When I try to run the migrations, I get the same error as when I run `php bin/console mautic:update:apply --finish` (the error above).

How can I complete the update to 4.2?

Also as a side note - Mautic thinks I am running 4.2 already.

---

<div class="post-metadata">

**Author:** ![tobsowo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/tobsowo/32/3096_2.png) [@tobsowo](https://forum.mautic.org/u/tobsowo)\
**Post date:** [March 1, 2022, 5:58pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/2 "2022-03-01T17:58:33Z")

</div>

Are you updating from the web? Starting with v5.0, you will only be able to update from CLI but get notification from web.

Try out this and see if it helps

> [@Error after upgrading to 4.2 clearing cache fails and error: Unknown column last\_built\_date in field list](https://forum.mautic.org/t/error-after-upgrading-to-4-2-from-4-unknown-column-last-built-date-in-field-list/22866/11):
>
> Thanks … we resume the cronjob and so far no errors after doing both @rcheesley and your suggestions to fix this issue. We may go ahead and trash this Mautic install since we installed it when 4.0 first came out last year and we really haven’t made the move over to it yet due to bugs we keep discovering on it so our are still in a “testing” stage. Our first install was done via zip file and now with new Marketplace which require composer install so we are checking to see if composer would wor…

---

<div class="post-metadata">

**Author:** ![cwmarketing](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/cwmarketing/32/2567_2.png) [@cwmarketing](https://forum.mautic.org/u/cwmarketing)\
**Post date:** [March 1, 2022, 6:09pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/3 "2022-03-01T18:09:50Z")

</div>

No I am updating via command line.

---

<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 1, 2022, 6:17pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/4 "2022-03-01T18:17:44Z")

</div>

Hi there,

What version are you updating from here?

You may have outstanding migrations if you have had incomplete updates in the past.

Does it do anything if you check in the UI for the schema updates?

> **[Mautic update failed - how to recover](https://docs.mautic.org/en/troubleshooting/update-failed#checking-for-schema-updates)**
>
> . Sometimes when updating Mautic, the process might stall or fail part way through. This can cause a problem, because it can cause Mautic to be inbetween two versions and often this can make the system unusable.. . . . . . Generally speaking, updates...

---

<div class="post-metadata">

**Author:** ![cwmarketing](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/cwmarketing/32/2567_2.png) [@cwmarketing](https://forum.mautic.org/u/cwmarketing)\
**Post date:** [March 1, 2022, 7:10pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/5 "2022-03-01T19:10:29Z")

</div>

I thought I was updating from 4.1 but perhaps some old updates didn’t finish completely.

If I try to check in the UI for schema I get a 500 server error.

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [March 1, 2022, 8:08pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/6 "2022-03-01T20:08:18Z")

</div>

Hi,

I had to play around with migrations to get it from Mautic 3 to 4 a bit too, because in previous versions of Mautic I have not executed update process completely, while I cannot remember the specific error I have a strong suspicion that your update error also comes from the same category of problems.

**A general note on migrations in Mautic core** : method isApplicable (or something very similar to that :)) is not really well implemented for all migrations thats why sometimes script ties to apply the migration even though you do not really need it.

**About the error itself and how to work around it** : A message from the log is saying that it cant renmae the index. You can triy to drop the index in question manually and then run the migration again. If that does not help see the steps below.

**Upgrade process** :

- backup your mautic instance (source and database) as there is a possibility you will have to do the process multiple times
- run php bin/console doctrine:migrations:migrate manually
- migrations process will fail but while you run this command you can see exectly in which migration the problem is.
- you now check the migration file of the failed migration, see what the migration is trying to do and adjust the database schema in a way so that migration can be applied (that usually means altering a table column)
- after you manually update the schema just enough for the migration to apply schema changes successfully you run the doctrine migrations process again
- this time it will either complete the migrations successfully or it will fail on the different migration, if it fails on different migration file you just inspect the failed migration fail again and repeat the process

**Skipping migrations**  
After applying the process above you may come in a situation when during the process of manually updating the database schema for the migration you will actually update the schema in the same way as the migration file would if it would be applied successfully. When this happen you might want to skip the migration. You can do that by manually inserting a record in migrations table in your database.

**Foreign keys**  
Some migrations might fail because of foreign key constraints, while FKs are important, you might encounter issues while trying to rescue the database, thats why you might want to turn off the foreign keys checks in the database before you start the migration, **just remember to turn the checks back on when you are done**.

I hope this helps, if you need further assistance let me know.

---

<div class="post-metadata">

**Author:** ![cwmarketing](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/cwmarketing/32/2567_2.png) [@cwmarketing](https://forum.mautic.org/u/cwmarketing)\
**Post date:** [March 1, 2022, 8:58pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/7 "2022-03-01T20:58:57Z")

</div>

Thanks, I’ll give this a try and see how it goes. Backing up now…

---

<div class="post-metadata">

**Author:** ![cwmarketing](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/cwmarketing/32/2567_2.png) [@cwmarketing](https://forum.mautic.org/u/cwmarketing)\
**Post date:** [March 1, 2022, 11:00pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/8 "2022-03-01T23:00:46Z")

</div>

I was able to complete the migrations using your guide!

I had to:

1. drop the index causing the error
2. manually complete another migration
3. add a row to the `ma_migrations` table to mark another migration as complete, as it was getting stuck but had already been done.

So after trying several times and performing those fixes, it finally ran to completion.

Do I need to worry about re-creating the index that I dropped?

---

<div class="post-metadata">

**Author:** ![cwmarketing](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/cwmarketing/32/2567_2.png) [@cwmarketing](https://forum.mautic.org/u/cwmarketing)\
**Post date:** [March 1, 2022, 11:48pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/9 "2022-03-01T23:48:27Z")

</div>

> [@mzagmajster](#):
>
> You can triy to drop the index in question manually and then run the migration again

So now I’m getting an error when trying to view a segment because of the missing segment:

`mautic.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\DriverException: "An exception occurred while executing 'SELECT DATE_FORMAT(t.date_added, '%Y-%m-%d') AS date, COUNT(*) AS count FROM ma_lead_event_log t USE INDEX (ma_IDX_SEARCH) WHERE (t.object = ?) AND (t.bundle = ?) AND (t.action = ?) AND (t.object_id = ?) AND (t.date_added BETWEEN ? AND ?) GROUP BY DATE_FORMAT(t.date_added, '%Y-%m-%d') ORDER BY DATE_FORMAT(t.date_added, '%Y-%m-%d') ASC LIMIT 29' with params ["segment", "lead", "added", "52", "2022-02-01 00:00:00", "2022-03-01 23:59:59"]: SQLSTATE[42000]: Syntax error or access violation: 1176 Key 'ma_IDX_SEARCH' doesn't exist in table 't'" at /var/www/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 128 {"exception":"[object] (Doctrine\\DBAL\\Exception\\DriverException(code: 0): An exception occurred while executing 'SELECT DATE_FORMAT(t.date_added, '%Y-%m-%d') AS date, COUNT(*) AS count FROM ma_lead_event_log t USE INDEX (ma_IDX_SEARCH) WHERE (t.object = ?) AND (t.bundle = ?) AND (t.action = ?) AND (t.object_id = ?) AND (t.date_added BETWEEN ? AND ?) GROUP BY DATE_FORMAT(t.date_added, '%Y-%m-%d') ORDER BY DATE_FORMAT(t.date_added, '%Y-%m-%d') ASC LIMIT 29' with params [\"segment\", \"lead\", \"added\", \"52\", \"2022-02-01 00:00:00\", \"2022-03-01 23:59:59\"]:\n\nSQLSTATE[42000]: Syntax error or access violation: 1176 Key 'ma_IDX_SEARCH' doesn't exist in table 't' at /var/www/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:128, Doctrine\\DBAL\\Driver\\PDO\\Exception(code: 42000): SQLSTATE[42000]: Syntax error or access violation: 1176 Key 'ma_IDX_SEARCH' doesn't exist in table 't' at /var/www/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18, PDOException(code: 42000): SQLSTATE[42000]: Syntax error or access violation: 1176 Key 'ma_IDX_SEARCH' doesn't exist in table 't' at /var/www/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:112)"} []`

How can I re-create this index?

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [March 2, 2022, 12:41am UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/10 "2022-03-02T00:41:08Z")

</div>

Try running the following command:

php bin/console doctrine:schema:update --dump-sql

It should display the statement for creating the index that is missing.

You can also try to run the migration that adds this index.

---

<div class="post-metadata">

**Author:** ![cwmarketing](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/cwmarketing/32/2567_2.png) [@cwmarketing](https://forum.mautic.org/u/cwmarketing)\
**Post date:** [March 2, 2022, 12:42am UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/11 "2022-03-02T00:42:24Z")

</div>

Thanks, before I saw your reply I did it by just looking at the error for the columns on the index and creating it that way:

`CREATE INDEX ma_IDX_SEARCH ON ma_lead_event_log (object, bundle, action, object_id, date_added)`

I can now view segments again.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [March 2, 2022, 9:43am UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/12 "2022-03-02T09:43:45Z")

</div>

I can see my PR [Segment view optimization by escopecz · Pull Request #10523 · mautic/mautic · GitHub](https://github.com/mautic/mautic/pull/10523) is to blame. It has 2 migrations in it for some reason (I’m not the author, I cherry-picked it from a colleague who left our team). I’m missing the full error in this forum thread. I can’t tell which of the 2 migration caused the problem. Can someone please provide full error that running the `bin/console doctrine:migrations:migrate` command outputs for you?

Update: From the commit messages it seems that the first migration was done without considering the table prefix. Since it was deployed to our development environment instances he created a second migration that fix the prefix. I should have caught that and merge those 2 migrations into one.

---

<div class="post-metadata">

**Author:** ![gathh](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/gathh/32/6515_2.png) [@gathh](https://forum.mautic.org/u/gathh)\
**Post date:** [March 3, 2022, 7:10am UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/13 "2022-03-03T07:10:07Z")

</div>

I also am struggling with updating.

When I run php bin/console doctrine:migrations:migrate I get this:

Migration 20201120122846 failed during Execution. Error An exception occurred while executing ’  
CREATE TABLE mau4m\_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\_CEFB88B5F639F774 (campaign\_id),  
INDEX IDX\_CEFB88B571F7E88B (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;  
':

Table ‘mau4m\_campaign\_summary’ already exists

In AbstractMySQLDriver.php line 57:

An exception occurred while executing ’  
CREATE TABLE mau4m\_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:date  
time\_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\_CEFB88B5F639F774 (campaign\_id),  
INDEX IDX\_CEFB88B571F7E88B (event\_id),  
UNIQUE INDEX campaign\_event\_date\_triggered (campaign\_id, ev  
ent\_id, date\_triggered),  
PRIMARY KEY(id)  
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` EN  
GINE = InnoDB ROW\_FORMAT = DYNAMIC;  
':

Table ‘mau4m\_campaign\_summary’ already exists

In StatementError.php line 19:

Table ‘mau4m\_campaign\_summary’ already exists

doctrine:migrations:migrate [–write-sql [WRITE-SQL]] [–dry-run] [–query-time] [–allow-no-migration] [–all-or-nothing [ALL-OR-NOTHING]] [–configuration [CONFIGURATION]] [–db-configuration [DB-CONFIGURATION]] [–db DB] [–em EM] [–shard SHARD] [-h|–help] [-q|–quiet] [-v|vv|vvv|–verbose] [-V|–version] [–ansi] [–no-ansi] [-n|–no-interaction] [-e|–env ENV] [–no-debug] [–] []

Any idea what I can do to fix this?

Running s/update/schema gives me: An error occurred while updating the database. Check log for more details.

This is in the log:

[2022-03-03 14:09:06] mautic.NOTICE: Doctrine\DBAL\Exception\TableExistsException: An exception occurred while executing ’ CREATE TABLE mau4m\_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\_CEFB88B5F639F774 (campaign\_id), INDEX IDX\_CEFB88B571F7E88B (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; ': Table ‘mau4m\_campaign\_summary’ already exists (uncaught exception) at /home/golfasia/engage.golfasia.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 57 while running console command `doctrine:migrations:migrate`    
[2022-03-03 14:09:06] mautic.WARNING: Command `doctrine:migrations:migrate` exited with status code 1    
[2022-03-03 14:09:06] mautic.ERROR: [UPGRADE ERROR] Exit code 1; Mautic Migrations \ Migrating up to 20220111202917 from 20201105120328 \ ++ migrating 20201120122846 \ → CREATE TABLE mau4m\_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\_CEFB88B5F639F774 (campaign\_id), INDEX IDX\_CEFB88B571F7E88B (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 mau4m\_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\_CEFB88B5F639F774 (campaign\_id), INDEX IDX\_CEFB88B571F7E88B (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; ': \ Table ‘mau4m\_campaign\_summary’ already exists \ In AbstractMySQLDriver.php line 57: \ An exception occurred while executing ’ CREATE TABLE mau4m\_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:date time\_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\_CEFB88B5F639F774 (campaign\_id), INDEX IDX\_CEFB88B571F7E88B (event\_id), UNIQUE INDEX campaign\_event\_date\_triggered (campaign\_id, ev ent\_id, date\_triggered), PRIMARY KEY(id) ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` EN GINE = InnoDB ROW\_FORMAT = DYNAMIC; ': \ Table ‘mau4m\_campaign\_summary’ already exists \ In StatementError.php line 19: \ Table ‘mau4m\_campaign\_summary’ already exists \ doctrine:migrations:migrate [–write-sql [WRITE-SQL]] [–dry-run] [–query-time] [–allow-no-migration] [–all-or-nothing [ALL-OR-NOTHING]] [–configuration [CONFIGURATION]] [–db-configuration [DB-CONFIGURATION]] [–db DB] [–em EM] [–shard SHARD] [-h|–help] [-q|–quiet] [-v|vv|vvv|–verbose] [-V|–version] [–ansi] [–no-ansi] [-n|–no-interaction] [-e|–env ENV] [–no-debug] [–] \

running php bin/console doctrine:migrations:status gives me:

== Configuration

```
>> Name: Mautic Migrations
>> Database Driver: mysqli
>> Database Host: localhost
>> Database Name: databasename-here
>> Configuration Source: manually configured
>> Version Table Name: mau4m_migrations
>> Version Column Name: version
>> Migrations Namespace: Mautic\Migrations
>> Migrations Directory: /path/app/migrations
>> Previous Version: 2020-11-02 13:35:46 (20201102133546)
>> Current Version: 2020-11-05 12:03:28 (20201105120328)
>> Next Version: 2020-11-20 12:28:46 (20201120122846)
>> Latest Version: 2022-01-11 20:29:17 (20220111202917)
>> Executed Migrations: 31
>> Executed Unavailable Migrations: 0
>> Available Migrations: 47
>> New Migrations: 16

```

Any help is appreciated

---

<div class="post-metadata">

**Author:** ![biggala2310](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/biggala2310/32/694_2.png) [@biggala2310](https://forum.mautic.org/u/biggala2310)\
**Post date:** [March 3, 2022, 1:36pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/14 "2022-03-03T13:36:23Z")

</div>

> [@escopecz](#):
>
> bin/console doctrine:migrations:migrate

```auto
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)Migrating up to 20220111202917 from 20210623071326

  ++ migrating 20201125155904

     -> ALTER TABLE `mlead_event_log` RENAME INDEX `IDX_SEARCH` TO `mIDX_SEARCH`
Migration 20201125155904 failed during Execution. Error An exception occurred while executing 'ALTER TABLE `mlead_event_log` RENAME INDEX `IDX_SEARCH` TO `mIDX_SEARCH`':

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INDEX `IDX_SEARCH` TO `mIDX_SEARCH`' at line 1

In AbstractMySQLDriver.php line 98:
                                                                               
  An exception occurred while executing 'ALTER TABLE `mlead_event_log` RENAME  
   INDEX `IDX_SEARCH` TO `mIDX_SEARCH`':                                       
                                                                               
  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i  
  n your SQL syntax; check the manual that corresponds to your MariaDB server  
   version for the right syntax to use near 'INDEX `IDX_SEARCH` TO `mIDX_SEAR  
  CH`' at line 1                                                               
                                                                               

In Exception.php line 18:
                                                                               
  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i  
  n your SQL syntax; check the manual that corresponds to your MariaDB server  
   version for the right syntax to use near 'INDEX `IDX_SEARCH` TO `mIDX_SEAR  
  CH`' at line 1                                                               
                                                                               

In PDOConnection.php line 132:
                                                                               
  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i  
  n your SQL syntax; check the manual that corresponds to your MariaDB server  
   version for the right syntax to use near 'INDEX `IDX_SEARCH` TO `mIDX_SEAR  
  CH`' at line 1                                                               
                                                                               

doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--all-or-nothing [ALL-OR-NOTHING]] [--configuration [CONFIGURATION]] [--db-configuration [DB-CONFIGURATION]] [--db DB] [--em EM] [--shard SHARD] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> [<version>]

```

---

<div class="post-metadata">

**Author:** ![biggala2310](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/biggala2310/32/694_2.png) [@biggala2310](https://forum.mautic.org/u/biggala2310)\
**Post date:** [March 3, 2022, 2:15pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/15 "2022-03-03T14:15:34Z")

</div>

> [@mzagmajster](#):
>
> doctrine:mgirations:migrate

I manualy deleted IDX\_SEARCH in phpmyadmin and run cron to migration. It helps. Thanks @mzagmajster!

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [March 3, 2022, 3:06pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/16 "2022-03-03T15:06:19Z")

</div>

> [@gathh](#):
>
> Table ‘mau4m\_campaign\_summary’ already exists

This is different error than this topic is about. It’s problem with this migration:

> <https://github.com/mautic/mautic/blob/926dcf3c8fa67f34389e5061070ea74aec567b41/app/migrations/Version20201120122846.php>

which was added in Mautic 4.1. I suspect the problem might be caused by the migration failing in the middle, the table was created and now only the constraints are missing. I’d suggest to solve it by running

```auto
bin/console doctrine:schema:update --dump-sql | grep campaign_summary

```

This will print the SQL queries you have to run to fix the summary table and the migration command. Run those queries directly on the database either via command line, PhpMyAdmin, Adminer, SequelPro or similar UI.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [March 3, 2022, 4:30pm UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/17 "2022-03-03T16:30:45Z")

</div>

I created fix for both issues with the campaign\_summary as well as the lead\_event\_log index. Both are reproducible.

> <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\>

---

<div class="post-metadata">

**Author:** ![gathh](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/gathh/32/6515_2.png) [@gathh](https://forum.mautic.org/u/gathh)\
**Post date:** [March 4, 2022, 1:57am UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/18 "2022-03-04T01:57:07Z")

</div>

Thank you so much for this tip.

I ran the command and then got this output:

```auto
ALTER TABLE mau4m_campaign_summary ADD CONSTRAINT FK_CEFB88B5F639F774 FOREIGN KEY (campaign_id) REFERENCES mau4m_campaigns (id);
ALTER TABLE mau4m_campaign_summary ADD CONSTRAINT FK_CEFB88B571F7E88B FOREIGN KEY (event_id) REFERENCES mau4m_campaign_events (id) ON DELETE CASCADE;
DROP INDEX campaign_event_date_triggered ON mau4m_campaign_summary;
CREATE UNIQUE INDEX mau4m_campaign_event_date_triggered ON mau4m_campaign_summary (campaign_id, event_id, date_triggered);

```

I then went to phymyadmin and ran the query and got this:

```auto
ALTER TABLE mau4m_campaign_summary ADD CONSTRAINT FK_CEFB88B5F639F774 FOREIGN KEY (campaign_id) REFERENCES mau4m_campaigns (id)
MySQL said: Documentation

#1005 - Can't create table `db_maut926`.`mau4m_campaign_summary` (errno: 150 "Foreign key constraint is incorrectly formed")

```

I think I am getting close but still far away 🙂

---

<div class="post-metadata">

**Author:** ![gathh](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/gathh/32/6515_2.png) [@gathh](https://forum.mautic.org/u/gathh)\
**Post date:** [March 4, 2022, 6:47am UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/19 "2022-03-04T06:47:25Z")

</div>

We manually updated the tables one by one and when i run /s/update/schema, I now get a green light, saying database has been updated. Also when i check the migration status, all is good.

However, now when I am opening an email to edit or load a customer detail, it won’t load at all (email) or it takes aaaages to load (customer detail page). What could be missing?

Thank you.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [March 4, 2022, 9:17am UTC](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/20 "2022-03-04T09:17:43Z")

</div>

Check [Troubleshooting | Mautic](https://docs.mautic.org/en/troubleshooting) and if it’s not related to this thread, please start a new one so we don’t mix several issues together.

[Next page](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867.md?page=2)
