Mautic Migration errors version 2.16.0

Your software
My Mautic version is: 2.16.0
My PHP version is: 7.1.33

Your problem
My problem is:

I received errors in my log file after the upgrade to 2.16.0.

[2020-02-19 00:10:36] mautic.ERROR: SCHEMA ERROR: An exception occurred while executing ‘SELECT f.alias, f.is_unique_identifer as is_unique, f.type, f.object FROM ma_lead_fields f WHERE f.object = ‘lead’ ORDER BY f.field_order ASC’: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘mautic.ma_lead_fields’ doesn’t exist
[2020-02-19 19:16:53] mautic.NOTICE: Doctrine\DBAL\Exception\DriverException: An exception occurred while executing ‘ALTER TABLE ma_lead_event_log DROP FOREIGN KEY FK_3364E8F155458D’: SQLSTATE[42000]: Syntax error or access violation: 1091 Can’t DROP ‘FK_3364E8F155458D’; check that column/key exists (uncaught exception) at /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 115 while running console command doctrine:migrations:migrate

It appears that the first error is not an issue and has been around for a few errors. The second error seems to be a concern as I don’t think the migration is completing.

If I manually run the migration I get the following errors in regards to missing Foreign keys.

Migrating up to 20190715065013 from 20180220212444

++ migrating 20180329185634

 -> ALTER TABLE ma_lead_event_log DROP FOREIGN KEY FK_3364E8F155458D

Migration 20180329185634 failed during Execution. Error An exception occurred while executing ‘ALTER TABLE ma_lead_event_log DROP FOREIGN KEY FK_3364E8F155458D’:

SQLSTATE[42000]: Syntax error or access violation: 1091 Can’t DROP ‘FK_3364E8F155458D’; check that column/key exists

[Doctrine\DBAL\Exception\DriverException]
An exception occurred while executing ‘ALTER TABLE ma_lead_event_log
DROP FOREIGN KEY FK_3364E8F155458D’:

SQLSTATE[42000]: Syntax error or access violation: 1091 Can’t DROP ’
FK_3364E8F155458D’; check that column/key exists

[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1091 Can’t DROP ’
FK_3364E8F155458D’; check that column/key exists

[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1091 Can’t DROP ’
FK_3364E8F155458D’; check that column/key exists

Steps I have tried to fix the problem: I’ve tried running the migration over manually and consistently get these errors. Is the lack of these foreign keys causing the migration to fail? Is there a command I can run to fix these missing foreign keys?

Did you try https:// mauticurl /s/update/schema ?

1 Like

Yes, it produces the same errors as running the migration task.

[2020-02-19 16:46:24] mautic.NOTICE: Doctrine\DBAL\Exception\DriverException: An exception occurred while executing ‘ALTER TABLE ma_lead_event_log DROP FOREIGN KEY FK_3364E8F155458D’: SQLSTATE[42000]: Syntax error or access violation: 1091 Can’t DROP ‘FK_3364E8F155458D’; check that column/key exists (uncaught exception) at /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 115 while running console command doctrine:migrations:migrate
[2020-02-19 16:46:24] mautic.ERROR: [UPGRADE ERROR] Exit code 1; Mautic Migrations \ Migrating up to 20190715065013 from 20180220212444 \ ++ migrating 20180329185634 \ -> ALTER TABLE ma_lead_event_log DROP FOREIGN KEY FK_3364E8F155458D Migration 20180329185634 failed during Execution. Error An exception occurred while executing ‘ALTER TABLE ma_lead_event_log DROP FOREIGN KEY FK_3364E8F155458D’: \ SQLSTATE[42000]: Syntax error or access violation: 1091 Can’t DROP ‘FK_3364E8F155458D’; check that column/key exists \ [Doctrine\DBAL\Exception\DriverException] An exception occurred while executing ‘ALTER TABLE ma_lead_event_log DROP FOREIGN KEY FK_3364E8F155458D’: \ SQLSTATE[42000]: Syntax error or access violation: 1091 Can’t DROP ‘FK_3364E8F155458D’; check that column/key exists \ [Doctrine\DBAL\Driver\PDOException] SQLSTATE[42000]: Syntax error or access violation: 1091 Can’t DROP ‘FK_3364E8F155458D’; check that column/key exists \ [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1091 Can’t DROP ‘FK_3364E8F155458D’; check that column/key exists \ doctrine:migrations:migrate [–write-sql] [–dry-run] [–query-time] [–allow-no-migration] [–configuration [CONFIGURATION]] [–db-configuration [DB-CONFIGURATION]] [–db DB] [–em EM] [–shard SHARD] [-h|–help] [-q|–quiet] [-v|vv|vvv|–verbose] [-V|–version] [–ansi] [–no-ansi] [-n|–no-interaction] [-s|–shell] [–process-isolation] [-e|–env ENV] [–no-debug] [–] \

Out of curiosity: Did you do the initial upgrade via GUI, or via console command?

no guarantees, but you might try (a backup and then) run
ALTER TABLE 'lead_event_log' ADD CONSTRAINT 'FK_3364E8F155458D' FOREIGN KEY ('lead_id') REFERENCES 'lead_event_log'('id') ON DELETE CASCADE ON UPDATE RESTRICT;

or rather, in your case
ALTER TABLE 'ma_lead_event_log' ADD CONSTRAINT 'FK_3364E8F155458D' FOREIGN KEY ('lead_id') REFERENCES 'ma_lead_event_log'('id') ON DELETE CASCADE ON UPDATE RESTRICT;

and try https:// mautic.url /s/update/schema once again

The upgrade was performed on the command line. The original database does not have this foreign key so I’m wondering if it was a failure on a previous upgrade.

In your example above, it is suppose to reference ‘ma_leads’(‘id’) instead of ‘ma_leads_event_log’(‘id’)?