# As usual, upgrade (to 4.2.2 this time) effed up my installation

**URL:** <https://forum.mautic.org/t/as-usual-upgrade-to-4-2-2-this-time-effed-up-my-installation/24106>\
**Category:** Mautic 4 Install/Upgrade Support\
**Created:** [May 15, 2022, 9:48pm UTC](https://forum.mautic.org/t/as-usual-upgrade-to-4-2-2-this-time-effed-up-my-installation/24106 "2022-05-15T21:48:07Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![modifiedcontent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/modifiedcontent/32/511_2.png) [@modifiedcontent](https://forum.mautic.org/u/modifiedcontent)\
**Post date:** [May 28, 2022, 4:03pm UTC](https://forum.mautic.org/t/as-usual-upgrade-to-4-2-2-this-time-effed-up-my-installation/24106/13 "2022-05-28T16:03:01Z")

</div>

It’s supposed to work together in clever/mysterious ways. I’m pretty sure you can’t just remove lines from this. OK for troubleshooting, but I guess I’ll have to put them back when I have a real solution to the database problem.

What does lead\_event\_log do? Is there any way to update/restore/change that table, so the upgrade script doesn’t choke on it again?

Apparently you can use this to clean up “something” involving lead\_event\_log:

```auto
php bin/console mautic:maintenance:cleanup --days-old=365 --dry-run

```

Without ‘–dry-run’ it executes the actual cleaning and testing again with it looks like old entries have been remove, so lead\_event\_log has been edited in a way that pleases Mautic?

Contacts still produce the same errors. doctrine:migration:migrate still produces the same error below. Cache clearing still does nothing.

```auto
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your S
  QL syntax; check the manual that corresponds to your MariaDB server version for the
   right syntax to use near 'INDEX `IDX_SEARCH` TO `mtc_IDX_SEARCH`' at line 1

```

doctrine:schema:update produces this error:

```auto
An exception occurred while executing 'ALTER TABLE mtc_oauth2_accesstokens CHANGE c
  lient_id client_id INT UNSIGNED NOT NULL, CHANGE user_id user_id INT UNSIGNED DEFAULT NULL, CHANGE token token VARCHAR(191) NOT NULL, CHANGE scope scope VARCHAR(191)
  DEFAULT NULL':

  SQLSTATE[HY000]: General error: 1832 Cannot change column 'client_id': used in a fo
  reign key constraint 'FK_818C32519EB6921'

```

Any other commands I could try? Trying to find a way to fix whatever in the database is conflicting with the upgrade script.

What does this mean?

```auto
Cannot change column 'client_id': used in a foreign key constraint 'FK_818C32519EB6921' at /home/myuser/public_html/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:128, Doctrine\\DBAL\\Driver\\PDO\\Exception(code: HY000): SQLSTATE[HY000]:

```

Apparently you can circumvent this by (temporarily) disabling foreign key checks in MySQL/MariaDB, with something like this:

```auto
ALTER TABLE table_name DISABLE KEYS;

```

Or

```auto
SET FOREIGN_KEY_CHECKS=0;

```

Or

```auto
SET foreign_key_checks = 0;
-- run some queries
SET foreign_key_checks = 1;

```

Applied to one of the offending pieces of SQL:

```auto
SET foreign_key_checks = 0;
ALTER TABLE mtc_oauth2_accesstokens CHANGE client_id client_id INT UNSIGNED NOT NULL,
CHANGE user_id user_id INT UNSIGNED DEFAULT NULL,
CHANGE token token VARCHAR(191) NOT NULL,
CHANGE scope scope VARCHAR(191) DEFAULT NULL;
SET foreign_key_checks = 1

```

This went through, but now when I try doctrine:schema:update --force I get another error:

```auto
LATEST FOREIGN KEY ERROR
------------------------
2022-05-28 11:08:55 0x7fa4040f2700 Error in foreign key constraint of table `mydb_mautic`.`mtc_oauth2_accesstokens`:
 FOREIGN KEY (client_id) REFERENCES mtc_oauth2_clients (id) ON DELETE CASCADE:
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
Please refer to https://mariadb.com/kb/en/library/foreign-keys/ for correct foreign key definition.
Alter table `mydb_mautic`.`mtc_oauth2_accesstokens` with foreign key constraint failed. Field type or character set for column 'client_id' does not mach referenced column 'id' near ' FOREIGN KEY (client_id) REFERENCES mtc_oauth2_clients (id) ON DELETE CASCADE'.

```

Trying to clear the cache I now get this error:

```auto
Unable to write in the "/home/myuser/public_html/mrktng/var/cache/prod" directory
  .

```

After messing with ownership/permission and endless cache clearing and --force whatever, the upgrade finally went through and individual Contact pages work again - but only if I remove all those lines from .htaccess. [I started another thread for that issue.](https://forum.mautic.org/t/mautic-upgrade-to-4-3-1-produces-403-http-error-unless-htaccess-security-lines-are-removed/24255)

---

_[View the full topic](https://forum.mautic.org/t/as-usual-upgrade-to-4-2-2-this-time-effed-up-my-installation/24106)._
