# Mautic 2.6.14 to Mautic 3 error: DB migration ALTER TABLE

**URL:** <https://forum.mautic.org/t/mautic-2-6-14-to-mautic-3-error-db-migration-alter-table/19676>\
**Category:** Mautic 3 - Install/Upgrade Support\
**Created:** [May 31, 2021, 7:29pm UTC](https://forum.mautic.org/t/mautic-2-6-14-to-mautic-3-error-db-migration-alter-table/19676 "2021-05-31T19:29:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![atz21](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/atz21/32/561_2.png) [@atz21](https://forum.mautic.org/u/atz21)\
**Post date:** [May 31, 2021, 7:29pm UTC](https://forum.mautic.org/t/mautic-2-6-14-to-mautic-3-error-db-migration-alter-table/19676/1 "2021-05-31T19:29:35Z")

</div>

Upgrading from Mautic 2.16.4 to Mautic 3.2.4  
My PHP version is: 7.3.28  
My MySQL/MariaDB version is: MySQL 5.7.32

Upgrading/installing via Mautic Dashboard on web (however, I also attempted the upgrade via the command line and received the same error)

These errors are showing in the Installer:

 ![Siteground screenshot 2](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/1/11479562d5bc125ebbd9f8e6c1d93bcd01a4784f.png)

Steps I have tried to fix the problem: I have unsuccessfully tried following steps outlined in this forum post (it may be an issue with my technical skills as I know how to access the command line, but am not very experienced troubleshooting with that): [Upgrade v2.16.0 to v3.0.2 - #15 by dennisameling](https://forum.mautic.org/t/upgrade-v2-16-0-to-v3-0-2/15404/15)

I’m looking for assistance/clarity on which commands could be run to help resolve the DB migration.

---

<div class="post-metadata">

**Author:** ![thomastc](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/thomastc/32/1454_2.png) [@thomastc](https://forum.mautic.org/u/thomastc)\
**Post date:** [June 1, 2021, 9:20am UTC](https://forum.mautic.org/t/mautic-2-6-14-to-mautic-3-error-db-migration-alter-table/19676/2 "2021-06-01T09:20:21Z")

</div>

I also ran into this error, and we’re not alone: [Error updating Mautic 2.16.4 to 3.2](https://forum.mautic.org/t/error-updating-mautic-2-16-4-to-3-2/17368)

There is an issue report: [SQL Syntax Error when Update to 3.1.0 · Issue #9180 · mautic/mautic · GitHub](https://github.com/mautic/mautic/issues/9180) I just posted a workaround there that worked for me, but I’m not entirely certain that it’s the “right” way, so please do make a backup and thoroughly test things afterwards.

---

<div class="post-metadata">

**Author:** ![atz21](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/atz21/32/561_2.png) [@atz21](https://forum.mautic.org/u/atz21)\
**Post date:** [June 2, 2021, 1:52pm UTC](https://forum.mautic.org/t/mautic-2-6-14-to-mautic-3-error-db-migration-alter-table/19676/3 "2021-06-02T13:52:37Z")

</div>

@thomastc great! I have a follow up question if you wouldn’t mind answering, it would be a huge help to me (apologies for my lack of skills/knowledge with shell):

Should I run the Mautic upgrade script, receive the error, and then run the SQL command from your comment? Or do I run the SQL command and the “bin/console doctrine:migrations:migrate:” command BEFORE running the Mautic upgrade script? If before, should I keep my PHP version at 7.1 (version which Mautic 2.6.14 works) or put that at 7.2+ (version which Mautic 3 needs) for running the scripts?

---

<div class="post-metadata">

**Author:** ![thomastc](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/thomastc/32/1454_2.png) [@thomastc](https://forum.mautic.org/u/thomastc)\
**Post date:** [June 3, 2021, 5:02am UTC](https://forum.mautic.org/t/mautic-2-6-14-to-mautic-3-error-db-migration-alter-table/19676/4 "2021-06-03T05:02:57Z")

</div>

Weren’t you already running PHP 7.3 though? In any case, the upgrade script will bail out if your PHP version is too low, before it does anything. So you need to do that first.

Then run:

```auto
php upgrade_v3.php

```

and get the SQL syntax error.

At this point you can (and probably should!) try the migration again:

```auto
php bin/console doctrine:migration:migrate

```

but for me, it failed with the same error.

So then I ran the two SQL statements:

```auto
ALTER TABLE email_stats ADD generated_sent_date DATE AS (CONCAT(YEAR(date_sent), "-", LPAD(MONTH(date_sent), 2, "0
"), "-", LPAD(DAY(date_sent), 2, "0"))) COMMENT '(DC2Type:generated)';
ALTER TABLE email_stats ADD INDEX `generated_sent_date_email_id`(generated_sent_date, email_id);

```

And finally tried the migrations again:

```auto
php bin/console doctrine:migration:migrate

```

This time it succeeded and I was running Mautic 3.2.4.

(There were a bunch of warnings about unknown registered migrations, going back to 2015 or something; I forget the exact message. To the best of my understanding, they are harmless.)

Remember to update your cron jobs to use `bin/console` instead of `app/console` at this point!

There are [some steps](https://docs.mautic.org/en/mautic-3-upgrade/upgrade-steps) after the database migration, which probably didn’t get executed in my case, most notably “restore user data”. Regardless, it seems I ended up with a working installation, including plugins and themes. Maybe the subsequent update to 3.3.3, which I performed immediately after, has taken care of that.

---

<div class="post-metadata">

**Author:** ![atz21](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/atz21/32/561_2.png) [@atz21](https://forum.mautic.org/u/atz21)\
**Post date:** [June 4, 2021, 8:19pm UTC](https://forum.mautic.org/t/mautic-2-6-14-to-mautic-3-error-db-migration-alter-table/19676/5 "2021-06-04T20:19:38Z")

</div>

Yes, I’ve been running PHP 7.3 before preforming the upgrade.

I ran the upgrade script, received the error, tried the migrations again using the script you provided, and received the same error.

When trying to run the ALTER TABLE commands, I received a syntax error:

> syntax error near unexpected token `(’

Below is a screenshot of the command and the resulting error. Can you tell where I’m going wrong?

 ![Syntax error from DB migration](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/1/13081c4d8cc84b38868b2b70db22c0eb93978b9b.png)

---

<div class="post-metadata">

**Author:** ![thomastc](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/thomastc/32/1454_2.png) [@thomastc](https://forum.mautic.org/u/thomastc)\
**Post date:** [June 5, 2021, 6:29am UTC](https://forum.mautic.org/t/mautic-2-6-14-to-mautic-3-error-db-migration-alter-table/19676/6 "2021-06-05T06:29:25Z")

</div>

They’re SQL statements, not shell commands, so you need to run them in a mysql shell, not in the system’s bash shell. You can type

```auto
mysql -hHOSTNAME -uUSERNAME -p DATABASENAME

```

to connect, replacing `HOSTNAME`, `USERNAME` and `DATABASENAME` as appropriate for your system. It’ll prompt you for the password if the rest of the arguments are correct. Then run the two SQL statements, and type `exit` or press Ctrl+D to exit the mysql shell.

If you have access to phpMyAdmin or a similar tool, you can use that to run SQL commands as well.

---

<div class="post-metadata">

**Author:** ![atz21](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/atz21/32/561_2.png) [@atz21](https://forum.mautic.org/u/atz21)\
**Post date:** [June 8, 2021, 4:01pm UTC](https://forum.mautic.org/t/mautic-2-6-14-to-mautic-3-error-db-migration-alter-table/19676/7 "2021-06-08T16:01:35Z")

</div>

@thomastc I think we’re getting close. Thank you for your patience and continued help! I was able to login to the MySQL database, but have received a new syntax error. I know next to nothing about MySQL syntax so I’m not sure where to start troubleshooting… does this error give you any insight into what is wrong?

 ![Syntax error from MySQL](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/f/f17801c3c8747ab6f767f59b508daf742ffc3c2a.png)

---

<div class="post-metadata">

**Author:** ![thomastc](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/thomastc/32/1454_2.png) [@thomastc](https://forum.mautic.org/u/thomastc)\
**Post date:** [June 8, 2021, 4:56pm UTC](https://forum.mautic.org/t/mautic-2-6-14-to-mautic-3-error-db-migration-alter-table/19676/8 "2021-06-08T16:56:06Z")

</div>

It looks like you missed a part of the query (`MONTH` is not there). Are you typing it all out by hand? Try copying and pasting instead 🙂

---

<div class="post-metadata">

**Author:** ![atz21](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/atz21/32/561_2.png) [@atz21](https://forum.mautic.org/u/atz21)\
**Post date:** [June 8, 2021, 10:28pm UTC](https://forum.mautic.org/t/mautic-2-6-14-to-mautic-3-error-db-migration-alter-table/19676/9 "2021-06-08T22:28:16Z")

</div>

You’re right, I missed part of the command (wow that’s embarrassing… ask for help and be totally inept 🙄). I am typing by hand-- long story, but I was spending more time messing up my connection (Control V doesn’t work) and googling about how to copy/paste in shell that it actually saved me time to type rather than continue researching.

Anyway-- IT WORKED!!! There was just one small thing I needed to change (I will write it out here in case someone else comes across this). When entering the MySQL command, I received the following error:

> ERROR 1146 (41S02) : Table ‘$MyDatabaseName.email\_stats’ doesn’t exist

I did a quick scan of the database table list via PHP MyAdmin. I saw that my tables all started with “maugk\_”. I’m not sure if that is unique to my Mautic setup and have no idea why/how that text string is there. But I re-entered your two MySQL commands and changed “email\_stats” to

> maugk\_email\_stats

And then it worked! I too received a warning about previously executed migrations in the database that are not registered migrations. I continued anyway and the migration occurred (I did receive an error of “Can’t DROP ‘maugk\_tweet\_text\_index’; check that column/key exists”. However I do not use Mautic to manage any Twitter/tweets so I’m not concerned with that piece. I did a quick check of my email stats, contacts, campaigns, etc. and it appears everything is working while running the new version of Mautic.

Thank you @thomastc! You rock!

---

<div class="post-metadata">

**Author:** ![thomastc](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/thomastc/32/1454_2.png) [@thomastc](https://forum.mautic.org/u/thomastc)\
**Post date:** [June 9, 2021, 7:28am UTC](https://forum.mautic.org/t/mautic-2-6-14-to-mautic-3-error-db-migration-alter-table/19676/10 "2021-06-09T07:28:49Z")

</div>

> I did a quick scan of the database table list via PHP MyAdmin. I saw that my tables all started with “maugk\_”. I’m not sure if that is unique to my Mautic setup and have no idea why/how that text string is there.

Good point, I forgot to mention that, glad you figured it out by yourself! The prefix is there as a (pretty thin) line of defense, in case some malicious script gains access to the database but isn’t clever enough to figure out what table prefix to use. It is randomly generated for each install.

> I did receive an error of “Can’t DROP ‘maugk\_tweet\_text\_index’; check that column/key exists”.

I didn’t see that error, but if the migration needed something gone that was already gone, it’s probably fine 🙂
