Error upgrading db while upgrading to 4.0.0-b1


I have tried to upgrade matomo to version 4.0.0-b1.

I have have done the following:

  • Backed up configuration and DB.
  • Configured the maintenance mode and stop recording statistics.
  • Downloaded and unzipped the matomo zip file.
  • Used “./console core:update”.

This tasks ended in the following error:
Executing ALTER TABLE matomo_session CHANGE id id VARCHAR(191);…
[X] Critical Error during the update process:

* /opt/matomo/core/Updates/4.0.0-b1.php:
Error trying to execute the migration 'ALTER TABLE `matomo_session` CHANGE `id` `id` VARCHAR(191);'.
The error was: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'AQBqYXZhLnV0aWwuVHJlZU1h8AEBAW9yZy5hcGFjaGUuY29tbW9ucy5iZWFud...' for key 'PRIMARY'

Can anyone help me with this? I’ve done some research but I didnt found anything.
Thanks you in advance.

Best regards


Matomo stores the session data (so data like: who is logged in, etc. ) in the matomo_session MySQL table. Each entry has a unique id which previously was 255 characters long. With Matomo 4 this changed to 191 characters and it seems like this shortening of all ids causes one of them to no longer be unique, which causes the error you see.

I think (but am pretty unsure, so don’t do this unless you trust your backups a lot or someone else can confirm this), deleting all data in the matomo_session table should not do any harm apart from causing every user to be logged out immediately.

Hello Lukas,

It worked, sadly I got another errors some corruption in a table and missing files.

I will open posts related to this other issues.

Thanks a lot!

1 Like