I’ve been updating Mautic since v2 and I guess I had some old problems with the DB schema.
I was on 3.3.1 and I was able to update to 3.3.4 no problem, but then all hell broke loose when I tried to update to 4.0
I was getting errors related to the oauth2_clients table foreign key constraints.
I wasted a lot of time trying to figure this out, finally what worked for me I created a brand new 3.3.4 install, allowed the installation wizard to create a new database.
I then dumped all of my existing Mautic database but I only dumped the data, I didn’t dump the DB schema at all.
I used this command to do it
mysqldump --skip-triggers --no-create-info --add-locks --complete-insert db_mautic | sed -r 's/LOCK TABLES (`[^`]+`)/TRUNCATE TABLE \1; \n\nLOCK TABLES \1/g' | gzip > .//db_mautic-data-only.sql.gz
I then restored this sql dump on the clean schema created from the clean 3.3.4 install.
I then noticed that a few tables were missing, notably the migrations table had not been re-created, and my custom form tables were missing. So I repeated the whole process again, but this time before importing my “data-only” dump I imported those missing tables.
I also noticed that the leads table no longer had a googleplus column, and a custom column I had added was missing. So I made those changes first.
I also noticed the emails table had some records with a ‘headers’ value of empty, I changed those to the default of ‘’ since it’s a json column.
Finally I imported my data-only dump on top of the clean 3.3.4 schema and received no errors.
I then visited mauticurl/s/update/schema and it executed 28 migrations and populated my migrations table.
I was then able to update to 4.0 without getting any errors.
At first the dashboard was giving me a 500 error, but after running bin/console cache:clear then it worked and everything seems good so far