# Migration error

**URL:** <https://forum.mautic.org/t/migration-error/26979>\
**Category:** Mautic 4 Install/Upgrade Support\
**Created:** [February 8, 2023, 3:32pm UTC](https://forum.mautic.org/t/migration-error/26979 "2023-02-08T15:32:03Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Yosu\_Cadilla](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/yosu_cadilla/32/6206_2.png) [@Yosu\_Cadilla](https://forum.mautic.org/u/Yosu_Cadilla)\
**Post date:** [February 16, 2023, 6:32pm UTC](https://forum.mautic.org/t/migration-error/26979/4 "2023-02-16T18:32:30Z")

</div>

I guess you could make a snapshot, remove the offending keys, do the migration, check consistency, add the keys back (if needed).

Sounds very familiar, similar errors were found when migrating from early M3 versions to late M3 versions for Mautic instances previously migrated from M2 to M3 due to a problem in the M2 to M3 migration code that was dormant until you needed to upgrade to a newer M3 version.

Could this still be related?

> <https://github.com/mautic/mautic/issues/9709>
>
> \[//\]: # ( Invisible comment: 
> IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII…I
> Before you create the issue:
> IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
> Search for similar report among other reported issues.
> Learn how to troubleshoot at https://www.mautic.org/docs/en/tips/troubleshooting.html
> Use drag&drop to attach images or other files )
> 
> \## Bug Description
> 
> When upgrading to 3.3 from 3.2.5 the migrations did not run correctly. The error was 
> 
> \`\`\`
> ALTER TABLE lead\_lists ADD category\_id INT UNSIGNED DEFAULT NULL -\> ALTER TABLE lead\_lists ADD CONSTRAINT FK\_6EC1522A12469DE2 FOREIGN KEY (category\_id) REFERENCES categor
> ies (id) ON DELETE SET NULL Migration 20210104171005 failed during Execution. Error An exception occurred while executing 'ALTER TABLE lead\_lists ADD CONSTRAINT FK\_6EC1522A12469DE2 FOREIGN K
> EY (category\_id) REFERENCES categories (id) ON DELETE SET NULL': \\ SQLSTATE\[HY000\]: General error: 1005 Can't create table \`#sql-965\_c385\` (errno: 150 "Foreign key constraint is incorrectly formed") 
> \`\`\`
> 
> The isse is, that in migration https://github.com/mautic/mautic/blob/3.3.0/app/migrations/Version20210104171005.php is run command 
> 
> \`\`\`
> ALTER TABLE {$this-\>prefix}lead\_lists ADD category\_id INT UNSIGNED DEFAULT NULL
> \`\`\`
> 
> Without explicitly set width of the column, in our case it created INT(10) and then the migration failed. After setting this field to INT(11) ran without an error.  
> 
> Safer to have 
> 
> \`\`\`
> ALTER TABLE {$this-\>prefix}lead\_lists ADD category\_id INT(11) UNSIGNED DEFAULT NULL
> \`\`\`
> 
> Probably the cause is the setting and version of Mysql server (5.5.5-10.2.16-MariaDB-10.2.16+maria~artful). 
> 
> Thanks
> 
> | Q | A
> | --- | ---
> | Mautic version | 3.2.5
> | PHP version | 7.4
> | Mysql version | 5.5.5-10.2.16-MariaDB-10.2.16+maria~artful
> | Browser | any
> 
> \### Steps to reproduce
> 1. Upgrade to 3.3.0 
> 
>  
> \### Log errors
> 
> ALTER TABLE lead\_lists ADD category\_id INT UNSIGNED DEFAULT NULL -\> ALTER TABLE lead\_lists ADD CONSTRAINT FK\_6EC1522A12469DE2 FOREIGN KEY (category\_id) REFERENCES categor
> ies (id) ON DELETE SET NULL Migration 20210104171005 failed during Execution. Error An exception occurred while executing 'ALTER TABLE lead\_lists ADD CONSTRAINT FK\_6EC1522A12469DE2 FOREIGN K
> EY (category\_id) REFERENCES categories (id) ON DELETE SET NULL': \\ SQLSTATE\[HY000\]: General error: 1005 Can't create table \`#sql-965\_c385\` (errno: 150 "Foreign key constraint is incorrectly formed") 
> 
> \[//\]: # ( Invisible comment:
> Please check for related errors in the latest log file in \[mautic root\]/app/log/ and/or the web server's logs and post them here. Be sure to remove sensitive information if applicable. )

Similar issues:

> [@MySQL error upgrading to 4.2](https://forum.mautic.org/t/mysql-error-upgrading-to-4-2/22867/20):
>
> 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.

> [@Error while upgrading from 3.3.4 to 4.0](https://forum.mautic.org/t/error-while-upgrading-from-3-3-4-to-4-0/20686):
>
> Your software My PHP version is : 7.4 My MySQL/MariaDB version is (delete as applicable): MySQL/MariaDB version 10.3.31-MariaDB-log-cll-lve Updating/Installing Errors I am: Updating Upgrading via : Web These errors are showing in the installer : These errors are showing in the Mautic log : [2021-08-30 18:44:08] console.CRITICAL: Error thrown while running command “doctrine:migrations:migrate --no-interaction --env=prod --no-debug”. Message: “An exception occurred while executing ‘ALTER T…

---

_[View the full topic](https://forum.mautic.org/t/migration-error/26979)._
