# Manually addressing foreign key constraint error in DB

**URL:** <https://forum.mautic.org/t/manually-addressing-foreign-key-constraint-error-in-db/24177>\
**Category:** Mautic 4 Install/Upgrade Support\
**Created:** [May 21, 2022, 3:49pm UTC](https://forum.mautic.org/t/manually-addressing-foreign-key-constraint-error-in-db/24177 "2022-05-21T15:49:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![crozilla](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/crozilla/32/2054_2.png) [@crozilla](https://forum.mautic.org/u/crozilla)\
**Post date:** [May 21, 2022, 3:49pm UTC](https://forum.mautic.org/t/manually-addressing-foreign-key-constraint-error-in-db/24177/1 "2022-05-21T15:49:23Z")

</div>

**Your software**  
_My PHP version is_ : 7.4  
_My MySQL/MariaDB version is_: MySQL v8.0

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

_These errors are showing in the installer_ :  
An exception occurred while executing ‘ALTER TABLE oauth2\_accesstokens CHANGE user\_id user\_id INT UNSIGNED DEFAULT NULL, CHANGE client\_id client\_id INT UNSIGNED NOT NULL, CHANGE token token VARCHAR(191) NOT NULL, CHANGE scope scope VARCHAR(191) DEFAULT NULL’:

SQLSTATE[HY000]: General error: 3780 Referencing column ‘user\_id’ and referenced column ‘id’ in foreign key constraint ‘FK\_3A18CA5AA76ED395’ are incompatible.

_These errors are showing in the Mautic log_ :  
[2022-05-19 12:29:31] mautic.NOTICE: Doctrine\DBAL\Exception\DriverException: An exception occurred while executing ‘ALTER TABLE oauth2\_accesstokens CHANGE user\_id user\_id INT UNSIGNED DEFAULT NULL, CHANGE client\_id client\_id INT UNSIGNED NOT NULL, CHANGE token token VARCHAR(191) NOT NULL, CHANGE scope scope VARCHAR(191) DEFAULT NULL’: SQLSTATE[HY000]: General error: 3780 Referencing column ‘user\_id’ and referenced column ‘id’ in foreign key constraint ‘FK\_XXXXXXXXXXXXXXXXXX’ are incompatible. (uncaught exception) at /home/thecroz/crosbyreport.com/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/

**Your problem**  
_My problem is_ :  
Foreign key constraint error

_Steps I have tried to fix the problem_ :  
I believe I can manually edit the DB table to fix this, but I want to make sure I am interpreting the failure (and solution) right:

In TABLE oauth2\_accesstokens, I need to CHANGE the user\_id to: “INT UNSIGNED DEFAULT NULL,” and then CHANGE the client\_id to “INT UNSIGNED NOT NULL,” and CHANGE the token to “VARCHAR(191) NOT NULL,” and CHANGE the scope to VARCHAR(191) DEFAULT NULL"

Am I interpreting the error/solution correctly?

---

<div class="post-metadata">

**Author:** ![crozilla](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/crozilla/32/2054_2.png) [@crozilla](https://forum.mautic.org/u/crozilla)\
**Post date:** [May 23, 2022, 1:56pm UTC](https://forum.mautic.org/t/manually-addressing-foreign-key-constraint-error-in-db/24177/2 "2022-05-23T13:56:56Z")

</div>

Didn’t work, can’t change any parameters because:  
"#3780 - Referencing column ‘user\_id’ and referenced column ‘id’ in foreign key constraint ‘FK\_XXXXXXXXXXXXXXXXXX’ are incompatible.

---

<div class="post-metadata">

**Author:** ![crozilla](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/crozilla/32/2054_2.png) [@crozilla](https://forum.mautic.org/u/crozilla)\
**Post date:** [May 23, 2022, 2:02pm UTC](https://forum.mautic.org/t/manually-addressing-foreign-key-constraint-error-in-db/24177/3 "2022-05-23T14:02:42Z")

</div>

Here’s where I am stuck after running, it’s a long list:

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

> **[Mautic foreign key constraits errors - Pastebin.com](https://pastebin.com/9MS8jyAm)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

**Author:** ![precords](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/precords/32/1504_2.png) [@precords](https://forum.mautic.org/u/precords)\
**Post date:** [July 8, 2022, 7:17am UTC](https://forum.mautic.org/t/manually-addressing-foreign-key-constraint-error-in-db/24177/4 "2022-07-08T07:17:37Z")

</div>

OK, I’m sure most people are getting this update error in mysql. We need some manual solutions to fix this!!!
