Hi all,
These migration issues have been plaguing me for a while now. I’ve been putting them on the “deal with later list” for as long as I could. Unfortunately (or fortunately depending on how you look at it), I finally had to sort it out as I’m running Mautic in a Kube cluster and can’t have restarting pods failing due to this.
I tried a few things including forcing “migrated” status on each migration, but that appears to cause some missing schema.
I was on a fresh install of Mautic using the 6.0.5 docker image.
NOTE: I found out the docker image environment variable option DOCKER_MAUTIC_RUN_MIGRATIONS does not do anything in 6.
The migrations that were failing for me were:
- Version20211020114811
- Version20211209022550
Version20211020114811 - Failing due to the missing index (can’t drop)
I shelled into the container, patched the file then proceeded - this only works because the migration is recorded as succeeding so it doesn’t run again when the container restarts and clears the patch.
Docker: docker run -it --entrypoint /bin/bash mautic/mautic:6.0.5-20250904-apache
Kuberenetes kubectl exec -it <pod-name> -- /bin/bash
Patch the file:
patch app/migrations/Version20211020114811.php << 'EOF'
> 58,64c58,67
< $this->addSql(
< sprintf(
< $dropIndexQuery,
< self::INDEX_COMPANY_MATCH,
< $this->getPrefixedTableName(self::COMPANIES_TABLE)
< )
< );
---
> if($schema->getTable($this->getPrefixedTableName(self::COMPANIES_TABLE))->hasIndex(self::INDEX_COMPANY_MATCH))
> {
> $this->addSql(
> sprintf(
> $dropIndexQuery,
> self::INDEX_COMPANY_MATCH,
> $this->getPrefixedTableName(self::COMPANIES_TABLE)
> )
> );
> }
EOF
Or if you’d prefer to patch manually:
Install an editor:
apt install nano
And add a check for the index before attempting to drop it:
if($schema->getTable($this->getPrefixedTableName(self::COMPANIES_TABLE))->hasIndex(self::INDEX_COMPANY_MATCH))
{
// Original code around line 58
$this->addSql(
sprintf(
$dropIndexQuery,
self::INDEX_COMPANY_MATCH,
$this->getPrefixedTableName(self::COMPANIES_TABLE)
)
);
}
That solved that first issue. Some people reported flagging it as migrated already. Since I attempted flagging all as migrated first and it did not work I was concerned about schema consistency.
Version20211209022550 - Failing due to roles table not existing.
This took a little more work. I inspected the migration and noticed that this migration was using Doctrine to get the Model instead of the table directly. It seems that process doesn’t apply the table prefix. I’m not sure if there is another setting that could be changed but my solution was to remove the table prefix entirely and update my configuration.
Shell into the container again (see previous patch) and modify the config:
nano /var/www/html/config/local.php
Set:
'db_table_prefix' => ''
Save and exit the shell.
Now connect to your database directly. This will vary depending on your set up, but for example:
mysql -h 127.0.0.1 -P 3306 -u root -p
Enter your password.
Set your database, e.g.
use mautic;
Now rename all tables to remove the prefix you had before. In my case I used mautic so all of my tables were mauticsomething which needed to be changed to something
Depending on your version you may have a different list of tables. I recommend running show tables; to get the full list.
For each table you’ll need to:
ALTER TABLE mauticsomething RENAME TO something;
For my version it was the following:
ALTER TABLE mauticasset_downloads RENAME TO asset_downloads;
ALTER TABLE mauticassets RENAME TO assets;
ALTER TABLE mauticaudit_log RENAME TO audit_log;
ALTER TABLE mauticbundle_grapesjsbuilder RENAME TO bundle_grapesjsbuilder;
ALTER TABLE mauticcache_items RENAME TO cache_items;
ALTER TABLE mauticcampaign_events RENAME TO campaign_events;
ALTER TABLE mauticcampaign_form_xref RENAME TO campaign_form_xref;
ALTER TABLE mauticcampaign_lead_event_failed_log RENAME TO campaign_lead_event_failed_log;
ALTER TABLE mauticcampaign_lead_event_log RENAME TO campaign_lead_event_log;
ALTER TABLE mauticcampaign_leadlist_xref RENAME TO campaign_leadlist_xref;
ALTER TABLE mauticcampaign_leads RENAME TO campaign_leads;
ALTER TABLE mauticcampaign_summary RENAME TO campaign_summary;
ALTER TABLE mauticcampaigns RENAME TO campaigns;
ALTER TABLE mauticcategories RENAME TO categories;
ALTER TABLE mauticchannel_url_trackables RENAME TO channel_url_trackables;
ALTER TABLE mauticcompanies RENAME TO companies;
ALTER TABLE mauticcompanies_leads RENAME TO companies_leads;
ALTER TABLE mauticcontact_export_scheduler RENAME TO contact_export_scheduler;
ALTER TABLE mauticcontact_merge_records RENAME TO contact_merge_records;
ALTER TABLE mauticdynamic_content RENAME TO dynamic_content;
ALTER TABLE mauticdynamic_content_lead_data RENAME TO dynamic_content_lead_data;
ALTER TABLE mauticdynamic_content_stats RENAME TO dynamic_content_stats;
ALTER TABLE mauticemail_assets_xref RENAME TO email_assets_xref;
ALTER TABLE mauticemail_copies RENAME TO email_copies;
ALTER TABLE mauticemail_list_excluded RENAME TO email_list_excluded;
ALTER TABLE mauticemail_list_xref RENAME TO email_list_xref;
ALTER TABLE mauticemail_stat_replies RENAME TO email_stat_replies;
ALTER TABLE mauticemail_stats RENAME TO email_stats;
ALTER TABLE mauticemail_stats_devices RENAME TO email_stats_devices;
ALTER TABLE mauticemails RENAME TO emails;
ALTER TABLE mauticemails_draft RENAME TO emails_draft;
ALTER TABLE mauticfocus RENAME TO focus;
ALTER TABLE mauticfocus_stats RENAME TO focus_stats;
ALTER TABLE mauticform_actions RENAME TO form_actions;
ALTER TABLE mauticform_fields RENAME TO form_fields;
ALTER TABLE mauticform_submissions RENAME TO form_submissions;
ALTER TABLE mauticforms RENAME TO forms;
ALTER TABLE mauticimports RENAME TO imports;
ALTER TABLE mauticintegration_entity RENAME TO integration_entity;
ALTER TABLE mauticip_addresses RENAME TO ip_addresses;
ALTER TABLE mauticlead_categories RENAME TO lead_categories;
ALTER TABLE mauticlead_companies_change_log RENAME TO lead_companies_change_log;
ALTER TABLE mauticlead_devices RENAME TO lead_devices;
ALTER TABLE mauticlead_donotcontact RENAME TO lead_donotcontact;
ALTER TABLE mauticlead_event_log RENAME TO lead_event_log;
ALTER TABLE mauticlead_fields RENAME TO lead_fields;
ALTER TABLE mauticlead_frequencyrules RENAME TO lead_frequencyrules;
ALTER TABLE mauticlead_ips_xref RENAME TO lead_ips_xref;
ALTER TABLE mauticlead_lists RENAME TO lead_lists;
ALTER TABLE mauticlead_lists_leads RENAME TO lead_lists_leads;
ALTER TABLE mauticlead_notes RENAME TO lead_notes;
ALTER TABLE mauticlead_points_change_log RENAME TO lead_points_change_log;
ALTER TABLE mauticlead_stages_change_log RENAME TO lead_stages_change_log;
ALTER TABLE mauticlead_tags RENAME TO lead_tags;
ALTER TABLE mauticlead_tags_xref RENAME TO lead_tags_xref;
ALTER TABLE mauticlead_utmtags RENAME TO lead_utmtags;
ALTER TABLE mauticleads RENAME TO leads;
ALTER TABLE mauticmessage_channels RENAME TO message_channels;
ALTER TABLE mauticmessage_queue RENAME TO message_queue;
ALTER TABLE mauticmessages RENAME TO messages;
ALTER TABLE mauticmigrations RENAME TO migrations;
ALTER TABLE mauticmonitor_post_count RENAME TO monitor_post_count;
ALTER TABLE mauticmonitoring RENAME TO monitoring;
ALTER TABLE mauticmonitoring_leads RENAME TO monitoring_leads;
ALTER TABLE mauticnotifications RENAME TO notifications;
ALTER TABLE mauticoauth2_accesstokens RENAME TO oauth2_accesstokens;
ALTER TABLE mauticoauth2_authcodes RENAME TO oauth2_authcodes;
ALTER TABLE mauticoauth2_clients RENAME TO oauth2_clients;
ALTER TABLE mauticoauth2_refreshtokens RENAME TO oauth2_refreshtokens;
ALTER TABLE mauticoauth2_user_client_xref RENAME TO oauth2_user_client_xref;
ALTER TABLE mauticpage_hits RENAME TO page_hits;
ALTER TABLE mauticpage_redirects RENAME TO page_redirects;
ALTER TABLE mauticpages RENAME TO pages;
ALTER TABLE mauticpermissions RENAME TO permissions;
ALTER TABLE mauticplugin_integration_settings RENAME TO plugin_integration_settings;
ALTER TABLE mauticplugins RENAME TO plugins;
ALTER TABLE mauticpoint_group_contact_score RENAME TO point_group_contact_score;
ALTER TABLE mauticpoint_groups RENAME TO point_groups;
ALTER TABLE mauticpoint_lead_action_log RENAME TO point_lead_action_log;
ALTER TABLE mauticpoint_lead_event_log RENAME TO point_lead_event_log;
ALTER TABLE mauticpoint_trigger_events RENAME TO point_trigger_events;
ALTER TABLE mauticpoint_triggers RENAME TO point_triggers;
ALTER TABLE mauticpoints RENAME TO points;
ALTER TABLE mauticpush_ids RENAME TO push_ids;
ALTER TABLE mauticpush_notification_list_xref RENAME TO push_notification_list_xref;
ALTER TABLE mauticpush_notification_stats RENAME TO push_notification_stats;
ALTER TABLE mauticpush_notifications RENAME TO push_notifications;
ALTER TABLE mauticreports RENAME TO reports;
ALTER TABLE mauticreports_schedulers RENAME TO reports_schedulers;
ALTER TABLE mauticroles RENAME TO roles;
ALTER TABLE mauticsaml_id_entry RENAME TO saml_id_entry;
ALTER TABLE mauticsms_message_list_xref RENAME TO sms_message_list_xref;
ALTER TABLE mauticsms_message_stats RENAME TO sms_message_stats;
ALTER TABLE mauticsms_messages RENAME TO sms_messages;
ALTER TABLE mauticstage_lead_action_log RENAME TO stage_lead_action_log;
ALTER TABLE mauticstages RENAME TO stages;
ALTER TABLE mauticsync_object_field_change_report RENAME TO sync_object_field_change_report;
ALTER TABLE mauticsync_object_mapping RENAME TO sync_object_mapping;
ALTER TABLE mautictweet_stats RENAME TO tweet_stats;
ALTER TABLE mautictweets RENAME TO tweets;
ALTER TABLE mauticuser_tokens RENAME TO user_tokens;
ALTER TABLE mauticusers RENAME TO users;
ALTER TABLE mauticvideo_hits RENAME TO video_hits;
ALTER TABLE mauticwebhook_events RENAME TO webhook_events;
ALTER TABLE mauticwebhook_logs RENAME TO webhook_logs;
ALTER TABLE mauticwebhook_queue RENAME TO webhook_queue;
ALTER TABLE mauticwebhooks RENAME TO webhooks;
ALTER TABLE mauticwidgets RENAME TO widgets;
Upon success I quit and restarted my container.
All migrations passed after that and I was able to log back it without resetting my installation again.
Final thoughts
I do think it is unfortunate that this hasn’t been officially fixed. I do understand trying to cover all use cases across multiple major releases in all environments is challenging, but this seems very entry level. It is so easy to reproduce. i.e. fresh install + restart container.
I haven’t tested version 7 at all, but I’m not sure if I’ll be sticking with Mautic long term due to some of these sorts of issues and scalability challenges due to it’s architecture.
Hopefully that helps a few people.