# 134 Executed Unavailable Migrations - unable to doctrine:schema:update - foreign key constraint 'FK\_3A18CA5A19EB6921'

**URL:** <https://forum.mautic.org/t/134-executed-unavailable-migrations-unable-to-doctrineupdate-foreign-key-constraint-fk-3a18ca5a19eb6921/15850>\
**Category:** Product Support\
**Created:** [August 28, 2020, 4:13pm UTC](https://forum.mautic.org/t/134-executed-unavailable-migrations-unable-to-doctrineupdate-foreign-key-constraint-fk-3a18ca5a19eb6921/15850 "2020-08-28T16:13:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![maumatic](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/maumatic/32/3284_2.png) [@maumatic](https://forum.mautic.org/u/maumatic)\
**Post date:** [August 28, 2020, 4:13pm UTC](https://forum.mautic.org/t/134-executed-unavailable-migrations-unable-to-doctrineupdate-foreign-key-constraint-fk-3a18ca5a19eb6921/15850/1 "2020-08-28T16:13:25Z")

</div>

**Your software**  
My Mautic version is: 3.1.0  
My PHP version is: 7.3.20  
My MariaDB version is : 10.5

**Your problem**  
My problem is: There are 134 Executed Unavailable Migrations

Here’s the migration status:

```
[root@vps mmm.mysite.com]# php bin/console cache:clear

 // Clearing the cache for the prod environment with debug false

 [OK] Cache for the "prod" environment (debug=false) was successfully cleared.

[root@vps mmm.mysite.com]# php bin/console doctrine:migration:status

```

== Configuration

```
>> Name: Mautic Migrations
>> Database Driver: pdo_mysql
>> Database Host: localhost
>> Database Name: mauticdb
>> Configuration Source: manually configured
>> Version Table Name: migrations
>> Version Column Name: version
>> Migrations Namespace: Mautic\Migrations
>> Migrations Directory: /var/www/mmm.mysite.com/app/migrations
>> Previous Version: 2020-08-05 18:57:14 (20200805185714)
>> Current Version: 2020-08-15 15:37:11 (20200815153711)
>> Next Version: Already at latest version
>> Latest Version: 2020-08-15 15:37:11 (20200815153711)
>> Executed Migrations: 147
>> Executed Unavailable Migrations: 134
>> Available Migrations: 13
>> New Migrations: 0
[root@vps mmm.mysite.com]#

```

Steps I have tried to fix the problem:

I’ve run `doctrine:migration:migrate` and `doctrine:schema:update` without success

```
[root@vps mmm.mysite.com]# php bin/console doctrine:migrations:migrate --no-interaction --env=prod --no-debug

[2020-08-28 18:08:42] Your database version (5.5.5-10.1.35-MariaDB) does not support generated columns. Upgrade at least to 10.2.6 and update `db_server_version` accordingly to get the speed improvements.

[2020-08-28 18:08:42]
[2020-08-28 18:08:42] Mautic Migrations
[2020-08-28 18:08:42]

[2020-08-28 18:08:42] WARNING! You have 134 previously executed migrations in the database that are not registered migrations.
[2020-08-28 18:08:42] >> 2015-04-02 00:00:00 (20150402000000)
[2020-08-28 18:08:42] >> 2015-05-04 00:00:00 (20150504000000)
[2020-08-28 18:08:42] >> 2015-05-21 00:00:00 (20150521000000)
[2020-08-28 18:08:42] >> 2015-07-18 00:00:00 (20150718000000)
[2020-08-28 18:08:42] >> 2015-07-24 00:00:00 (20150724000000)
[2020-08-28 18:08:42] >> 2015-08-01 00:00:00 (20150801000000)
...
...
[2020-08-28 18:08:42] >> 2018-12-04 00:00:00 (20181204000000)
[2020-08-28 18:08:42] >> 2019-07-15 06:50:13 (20190715065013)
[2020-08-28 18:08:42] No migrations to execute.
[root@vps mmm.mysite.com]# php bin/console doctrine:schema:update --force

 Updating database schema...

In AbstractMySQLDriver.php line 106:

  An exception occurred while executing 'ALTER TABLE oauth2_accesstokens CHANGE client_id client_id INT UNSIGNED NOT NULL, CHANGE user_id user_id INT UNSIGNED NOT NULL, CHANGE token token VARCHAR(191) NOT NULL, CHANGE expires_at expires_at BIGINT DEFAULT NULL, CHANGE s
  cope scope VARCHAR(191) DEFAULT NULL':

  SQLSTATE[HY000]: General error: 1832 Cannot change column 'client_id': used in a foreign key constraint 'FK_3A18CA5A19EB6921'

In PDOConnection.php line 80:

  SQLSTATE[HY000]: General error: 1832 Cannot change column 'client_id': used in a foreign key constraint 'FK_3A18CA5A19EB6921'

In PDOConnection.php line 75:

  SQLSTATE[HY000]: General error: 1832 Cannot change column 'client_id': used in a foreign key constraint 'FK_3A18CA5A19EB6921'

doctrine:schema:update [--complete] [--dump-sql] [-f|--force] [--em [EM]] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>

[root@vps mmm.mysite.com]#

```

Any idea on how to fix that ?  
Thanks for any hint.

---

<div class="post-metadata">

**Author:** ![madpet](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/madpet/32/1131_2.png) [@madpet](https://forum.mautic.org/u/madpet)\
**Post date:** [September 2, 2020, 12:26pm UTC](https://forum.mautic.org/t/134-executed-unavailable-migrations-unable-to-doctrineupdate-foreign-key-constraint-fk-3a18ca5a19eb6921/15850/2 "2020-09-02T12:26:14Z")

</div>

Hi @maumatic please see my detailed explanation [over here](https://forum.mautic.org/t/should-doctrinemigrate-and-doctrineupdate-force-ever-be-run-manually/15821/3). It should answer the question 😃

---

<div class="post-metadata">

**Author:** ![maumatic](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/maumatic/32/3284_2.png) [@maumatic](https://forum.mautic.org/u/maumatic)\
**Post date:** [September 2, 2020, 2:01pm UTC](https://forum.mautic.org/t/134-executed-unavailable-migrations-unable-to-doctrineupdate-foreign-key-constraint-fk-3a18ca5a19eb6921/15850/3 "2020-09-02T14:01:08Z")

</div>

Thank you very much @madpet 🙂

With your help I think I fixed the 134 “`Executed Unavailable Migrations`” problem.

Now I still have the `doctrine:schema:update` which is failing with the message:  
`General error: 1832 Cannot change column 'client_id': used in a foreign key constraint 'FK_3A18CA5A19EB6921'`

When I run `doctrine:schema:update --dump-sql` I have more than 100 SQL statements to be executed to bring my database up to date. So far it’s working ok like that but I fear one day it won’t anymore, so I still would like to do this update.

Any hint about fixing this foreign key constraint ?

---

<div class="post-metadata">

**Author:** ![madpet](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/madpet/32/1131_2.png) [@madpet](https://forum.mautic.org/u/madpet)\
**Post date:** [September 2, 2020, 3:07pm UTC](https://forum.mautic.org/t/134-executed-unavailable-migrations-unable-to-doctrineupdate-foreign-key-constraint-fk-3a18ca5a19eb6921/15850/4 "2020-09-02T15:07:55Z")

</div>

I can’t help you with the foreign key error. I suppose you need to debug exactly what is going on. Once way is to use `doctrine:schema:update --dump-sql` to see what queries are needed and then simply run them manually one at a time in the MySQL console. Then eventually you will hit the one that causes the error and you may have a better idea of why.

Alternatively, you can try the `doctrine:schema:update --force --complete` to force the database to drop anything not reflected in the mapping information, but that might be very risky as it can cause you to lose data so I would recommend the first strategy first.

---

<div class="post-metadata">

**Author:** ![maumatic](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/maumatic/32/3284_2.png) [@maumatic](https://forum.mautic.org/u/maumatic)\
**Post date:** [September 3, 2020, 8:56am UTC](https://forum.mautic.org/t/134-executed-unavailable-migrations-unable-to-doctrineupdate-foreign-key-constraint-fk-3a18ca5a19eb6921/15850/5 "2020-09-03T08:56:19Z")

</div>

> [@maumatic](#):
>
> General error: 1832 Cannot change column ‘client\_id’: used in a foreign key constraint ‘FK\_3A18CA5A19EB6921’

So here’s what I tried to solve this foreign key problem: I disabled the foreign key checks in mysql and then tried to run the first SQL statement given by `doctrine:schema:update --dump-sql`

```
MariaDB [mauticdb]> SET foreign_key_checks = 0;
Query OK, 0 rows affected (0.001 sec)

MariaDB [mauticdb]> ALTER TABLE oauth2_accesstokens CHANGE client_id client_id INT UNSIGNED NOT NULL, CHANGE user_id user_id INT UNSIGNED NOT NULL, CHANGE token token VARCHAR(191) NOT NULL, CHANGE expires_at expires_at BIGINT DEFAULT NULL, CHANGE scope scope VARCHAR(191) DEFAULT NULL;
ERROR 1025 (HY000): Error on rename of './mauticdb/#sql-alter-3aa-6a7d2' to './mauticdb/oauth2_accesstokens' (errno: 150 "Foreign key constraint is incorrectly formed")
MariaDB [mauticdb]> desc oauth2_accesstokens;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| client_id | int(11) | NO | MUL | NULL | |
| user_id | int(11) | NO | MUL | NULL | |
| token | varchar(255) | NO | UNI | NULL | |
| expires_at | bigint(20) | YES | | NULL | |
| scope | varchar(255) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
6 rows in set (0.001 sec)

MariaDB [mauticdb]>

```

So it failed and I stopped here. Any hint on how to get the tables updated ?

---

<div class="post-metadata">

**Author:** ![madpet](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/madpet/32/1131_2.png) [@madpet](https://forum.mautic.org/u/madpet)\
**Post date:** [September 4, 2020, 7:25am UTC](https://forum.mautic.org/t/134-executed-unavailable-migrations-unable-to-doctrineupdate-foreign-key-constraint-fk-3a18ca5a19eb6921/15850/6 "2020-09-04T07:25:54Z")

</div>

Nope, sorry. I don’t know anything about oauth2 or foreign keys in this context. Hopefully someone else can assist.

---

<div class="post-metadata">

**Author:** ![nilyin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/nilyin/32/613_2.png) [@nilyin](https://forum.mautic.org/u/nilyin)\
**Post date:** [September 10, 2020, 6:59pm UTC](https://forum.mautic.org/t/134-executed-unavailable-migrations-unable-to-doctrineupdate-foreign-key-constraint-fk-3a18ca5a19eb6921/15850/7 "2020-09-10T18:59:56Z")

</div>

I have same problem after upgrading to 3.1.0 from 3.0.2 and after trying to check database scheme.

 ![schema_error](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/9/9e8615f758dc8aab0da1362b8696b3d6326b83af.png) .

In my case all is very strange as mysql doesn’t properly respond to  
SET foreign\_key\_checks = 0;  
and throws a lot of table constraints’ errors.

I have actually tried manually drop FOREIGN KEYS one by one for every table. it looks like that it works this way, but I gave up for a while as it takes too much time.

I plan to drop the full mautic database and restore from backup… hopefully it will change strange behavior, that I faced after db migration…

I use mysql Ver 14.14 Distrib 5.7.29-32, for Linux (x86\_64) using 6.2

---

<div class="post-metadata">

**Author:** ![TBarregren](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/tbarregren/32/66_2.png) [@TBarregren](https://forum.mautic.org/u/TBarregren)\
**Post date:** [September 10, 2020, 7:52pm UTC](https://forum.mautic.org/t/134-executed-unavailable-migrations-unable-to-doctrineupdate-foreign-key-constraint-fk-3a18ca5a19eb6921/15850/8 "2020-09-10T19:52:11Z")

</div>

I have the exact same problem. I couldn’t find any bug report, so I created one: [https://github.com/mautic/mautic/issues/9185](https://github.com/mautic/mautic/issues/9185)

---

<div class="post-metadata">

**Author:** ![madpet](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/madpet/32/1131_2.png) [@madpet](https://forum.mautic.org/u/madpet)\
**Post date:** [September 21, 2020, 10:13am UTC](https://forum.mautic.org/t/134-executed-unavailable-migrations-unable-to-doctrineupdate-foreign-key-constraint-fk-3a18ca5a19eb6921/15850/9 "2020-09-21T10:13:12Z")

</div>

@maumatic If you still have the problem, try looking here for an explanation and recommendations to fix: [https://github.com/mautic/mautic/issues/9129#issuecomment-696010876](https://github.com/mautic/mautic/issues/9129#issuecomment-696010876)

---

<div class="post-metadata">

**Author:** ![maumatic](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/maumatic/32/3284_2.png) [@maumatic](https://forum.mautic.org/u/maumatic)\
**Post date:** [February 7, 2021, 6:55am UTC](https://forum.mautic.org/t/134-executed-unavailable-migrations-unable-to-doctrineupdate-foreign-key-constraint-fk-3a18ca5a19eb6921/15850/10 "2021-02-07T06:55:16Z")

</div>

I could finally update my database scheme, I explained how I did here:

> <https://github.com/mautic/mautic/issues/9129#issuecomment-774616000>
>
> Bug Description
> I've had a few different SQL migration errors since updating to 3.1.0 from 2.16.3. Most I've been able to figure...
