# Database migration error FOREIGN KEY constraint

**URL:** https://forum.mautic.org/t/database-migration-error-foreign-key-constraint/18413
**Category:** Mautic 3 - Install/Upgrade Support
**Created:** [March 3, 2021, 10:49am UTC](https://forum.mautic.org/t/database-migration-error-foreign-key-constraint/18413 "2021-03-03T10:49:39Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pboisdenghien](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/pboisdenghien/32/1712_2.png) [@pboisdenghien](https://forum.mautic.org/u/pboisdenghien)
#### Post date: [March 3, 2021, 10:49am UTC](https://forum.mautic.org/t/database-migration-error-foreign-key-constraint/18413/1 "2021-03-03T10:49:39Z")

</div>

\*\*Mautic 3.3  
_My PHP version is_ : 7.3.2.6  
\*My MySQL 8.0.22 - MySQL Community Server - GPL

**Updating/Installing Errors**

## Database migration issue with the folowing error, any help will be appreciate

Updating database schema…  
In AbstractMySQLDriver.php line 106:

An exception occurred while executing ‘ALTER TABLE ma\_oauth2\_accesstokens A  
DD CONSTRAINT FK\_AD7042B419EB6921 FOREIGN KEY (client\_id) REFERENCES ma\_oau  
th2\_clients (id) ON DELETE CASCADE’:

SQLSTATE[HY000]: General error: 3780 Referencing column ‘client\_id’ and ref  
erenced column ‘id’ in foreign key constraint ‘FK\_AD7042B419EB6921’ are inc  
ompatible.

In PDOConnection.php line 80:  
SQLSTATE[HY000]: General error: 3780 Referencing column ‘client\_id’ and ref  
erenced column ‘id’ in foreign key constraint ‘FK\_AD7042B419EB6921’ are inc  
ompatible.

In PDOConnection.php line 75:  
SQLSTATE[HY000]: General error: 3780 Referencing column ‘client\_id’ and ref  
erenced column ‘id’ in foreign key constraint ‘FK\_AD7042B419EB6921’ are inc  
ompatible.

---

<div class="post-metadata">

### Author: ![hhjchen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/hhjchen/32/2326_2.png) [@hhjchen](https://forum.mautic.org/u/hhjchen)
#### Post date: [July 20, 2021, 6:16am UTC](https://forum.mautic.org/t/database-migration-error-foreign-key-constraint/18413/2 "2021-07-20T06:16:31Z")

</div>

@pboisdenghien were you able to get through this? If so, could you share? I’m seeing a similar error. Thx!

---

<div class="post-metadata">

### Author: ![aerendir](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/aerendir/32/1050_2.png) [@aerendir](https://forum.mautic.org/u/aerendir)
#### Post date: [February 18, 2022, 3:52pm UTC](https://forum.mautic.org/t/database-migration-error-foreign-key-constraint/18413/3 "2022-02-18T15:52:44Z")

</div>

Did you solved this? I’m facing the same issue (and trying to fix it, but it is really hard and annoying 🤬)

---

<div class="post-metadata">

### Author: ![aerendir](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/aerendir/32/1050_2.png) [@aerendir](https://forum.mautic.org/u/aerendir)
#### Post date: [February 18, 2022, 3:59pm UTC](https://forum.mautic.org/t/database-migration-error-foreign-key-constraint/18413/4 "2022-02-18T15:59:51Z")

</div>

I’ve just replied here giving a bit more context about the issue: it is the same issue

> [@Error Updating from Mautic 3.0 --\>3.01](https://forum.mautic.org/t/error-updating-from-mautic-3-0-3-01/15038/11):
>
> Dropping the foreign key doesn’t work. Once dropped, running a bin/console doctrine:schema:update --force tries to recreate the foreign key, but the query results in an error: An exception occurred while executing ‘ALTER TABLE \*\_oauth2\_accesstokens ADD CONSTRAINT FK\_E6019FAD19EB6921 FOREIGN KEY (client\_id) REFERENCES \*\_oauth2\_clients (id) ON DELETE CASCADE’: SQLSTATE[HY000]: General error: 3780 Referencing column ‘client\_id’ and referenced column ‘id’ in foreign key constraint ‘FK\_E6019FAD19…

---

<div class="post-metadata">

### Author: ![aficio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/aficio/32/12659_2.png) [@aficio](https://forum.mautic.org/u/aficio)
#### Post date: [July 8, 2024, 1:59am UTC](https://forum.mautic.org/t/database-migration-error-foreign-key-constraint/18413/5 "2024-07-08T01:59:57Z")

</div>

Already posted in the referenced thread, but in case someone here still has the same problem: I [created a tool](https://github.com/aficiomaquinas/mautic-fix-db-ai) to address these issues. I was able to fix the problem in the end, although it required hundreds of SQL queries.
