Skip to content

Freeform Upgrade Failure (4.1.28 → 5.x) – Migration Error: “Table already exists” During Form Handle Migration #2453

@AMUNIRDGT

Description

@AMUNIRDGT

What happened?

We’re attempting to upgrade Freeform from version 4.1.28 to the latest 5.x release in our development environment, but the migration continually fails during the m230101_100010_FF4to5_MigrateForms step.

I previously had a very similar issue locally (GitHub issue: #2289), which was resolved by removing legacy Freeform tables. We applied the same cleanup on our dev database, but the upgrade is still failing with a nearly identical error.

Error During Migration

rename table {{%freeform_submissions_cancel_3}} to {{%tmp_c58e4}} ...Exception: SQLSTATE[42S01]:
Base table or view already exists: 1050 Table 'craft_tmp_c58e4' already exists
The SQL being executed was:
RENAME TABLE craft_freeform_submissions_cancel_3 TO craft_tmp_c58e4

The migration then aborts and rolls back.

Forms in Database

SELECT id,name,handle FROM craft_freeform_forms;
+----+---------------------------------+------------------+
| id | name | handle |
+----+---------------------------------+------------------+
| 1 | Contact | contact |
| 2 | Newsletters | newsletters |
| 3 | Cancel | cancel |
| 4 | Book consultation - Contact me | contact-me |
| 5 | Reschedule | reschedule |
| 6 | Book consultation - Existing | contact-existing |
| 7 | Book consultation - Steps | contact-steps |
+----+---------------------------------+------------------+

Existing Submission Tables

SHOW TABLES LIKE 'craft_freeform_submissions_%';
+---------------------------------------------------+
| Tables_in_craft_db (craft_freeform_submissions_%) |
+---------------------------------------------------+
| craft_freeform_submissions_cancel_3 |
| craft_freeform_submissions_contact_1 |
| craft_freeform_submissions_contact_existing_6 |
| craft_freeform_submissions_contact_me_4 |
| craft_freeform_submissions_contact_steps_7 |
| craft_freeform_submissions_newsletters_2 |
| craft_freeform_submissions_reschedule_5 |
+---------------------------------------------------+

What We’ve Tried

  • Removing legacy Freeform tables (as advised in my earlier GitHub issue).
  • Restoring DB backups and reattempting the upgrade multiple times.
  • Confirming that form IDs match submission tables.
  • Running the migration via both the CP and CLI (php craft up).

Despite this, migrations continue to fail at the same point with the tmp_* table already existing.

Request

Could you please help us diagnose why the migration is attempting to rename a table into a tmp_c58e4 table that already exists?
Is this a known issue, or is there additional cleanup required beyond removing legacy Freeform tables?
Any guidance would be greatly appreciated—we’re currently blocked from upgrading.

Errors and Stack Trace (if available)

applying m230101_100010_FF4to5_MigrateForms
> create index craft_idx_wlflgutphozxdptudmrxwafjtjnypcovratz on {{%freeform_forms}} (order) ... done (time: 0.072s)
> update in {{%freeform_forms}} ... done (time: 0.012s)
> update in {{%freeform_forms}} ... done (time: 0.007s)
> update in {{%freeform_forms}} ... done (time: 0.007s)
> update in {{%freeform_forms}} ... done (time: 0.007s)
> update in {{%freeform_forms}} ... done (time: 0.008s)
> update in {{%freeform_forms}} ... done (time: 0.008s)
> update in {{%freeform_forms}} ... done (time: 0.014s)
> rename table {{%freeform_submissions_cancel_3}} to {{%tmp_c58e4}} ...Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'craft_tmp_c58e4' already exists

The SQL being executed was: RENAME TABLE `craft_freeform_submissions_cancel_3` TO `craft_tmp_c58e4` (/home/site/wwwroot/vendor/yiisoft/yii2/db/Schema.php:676)

#0 /home/site/wwwroot/vendor/yiisoft/yii2/db/Command.php(1325): yii\db\Schema->convertException(Object(PDOException), 'RENAME TABLE `c...')

#1 /home/site/wwwroot/vendor/yiisoft/yii2/db/Command.php(1120): yii\db\Command->internalExecute('RENAME TABLE `c...')

#2 /home/site/wwwroot/vendor/craftcms/cms/src/helpers/Db.php(1348): yii\db\Command->execute()

#3 /home/site/wwwroot/vendor/craftcms/cms/src/db/Migration.php(412): craft\helpers\Db::renameTable('{{%freeform_sub...', '{{%tmp_c58e4}}', Object(craft\db\Connection))

#4 /home/site/wwwroot/vendor/solspace/craft-freeform/packages/plugin/src/migrations/m230101_100010_FF4to5_MigrateForms.php(193): craft\db\Migration->renameTable('{{%freeform_sub...', '{{%tmp_c58e4}}')

#5 /home/site/wwwroot/vendor/solspace/craft-freeform/packages/plugin/src/migrations/m230101_100010_FF4to5_MigrateForms.php(20): Solspace\Freeform\migrations\m230101_100010_FF4to5_MigrateForms->applyFormHandleChangesToMatchingSubmissionsTable()

#6 /home/site/wwwroot/vendor/craftcms/cms/src/db/Migration.php(50): Solspace\Freeform\migrations\m230101_100010_FF4to5_MigrateForms->safeUp()

#7 /home/site/wwwroot/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(758): craft\db\Migration->up()

#8 /home/site/wwwroot/vendor/craftcms/cms/src/console/controllers/MigrateController.php(373): yii\console\controllers\BaseMigrateController->migrateUp('m230101_100010_...')

#9 [internal function]: craft\console\controllers\MigrateController->actionAll()

#10 /home/site/wwwroot/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)

#11 /home/site/wwwroot/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)

#12 /home/site/wwwroot/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('all', Array)

#13 /home/site/wwwroot/vendor/craftcms/cms/src/console/controllers/MigrateController.php(192): yii\console\Controller->runAction('all', Array)

#14 /home/site/wwwroot/vendor/yiisoft/yii2/base/Module.php(552): craft\console\controllers\MigrateController->runAction('all', Array)

#15 /home/site/wwwroot/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)

#16 /home/site/wwwroot/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('migrate/all', Array)

#17 /home/site/wwwroot/vendor/yiisoft/yii2/base/Controller.php(212): craft\console\Application->runAction('migrate/all', Array)

#18 /home/site/wwwroot/vendor/craftcms/cms/src/console/Controller.php(207): yii\base\Controller->run('migrate/all', Array)

#19 /home/site/wwwroot/vendor/craftcms/cms/src/console/controllers/UpController.php(60): craft\console\Controller->run('migrate/all', Array)

#20 [internal function]: craft\console\controllers\UpController->actionIndex()

#21 /home/site/wwwroot/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)

#22 /home/site/wwwroot/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)

#23 /home/site/wwwroot/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('', Array)

#24 /home/site/wwwroot/vendor/craftcms/cms/src/console/ControllerTrait.php(88): yii\console\Controller->runAction('', Array)

#25 /home/site/wwwroot/vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction('', Array)

#26 /home/site/wwwroot/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('', Array)

#27 /home/site/wwwroot/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('up', Array)

#28 /home/site/wwwroot/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('up', Array)

#29 /home/site/wwwroot/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('up', Array)

#30 /home/site/wwwroot/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))

#31 /home/site/wwwroot/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))

#32 /home/site/wwwroot/craft(27): yii\base\Application->run()

#33 {main}

*** failed to apply m230101_100010_FF4to5_MigrateForms (time: 0.896s)
 
 
39 from 113 migrations were applied.
 
Migration failed. The rest of the migrations are canceled.
 
Restore the database backup? (yes|no) [yes]:no
 
Restore a database backup before trying again.
 
Aborting remaining tasks.
 
MySQL [craft_db]> SELECT id,name,handle FROM craft_freeform_forms;

+----+---------------------------------+------------------+

| id | name                            | handle           |

+----+---------------------------------+------------------+

|  1 | Contact                         | contact          |

|  2 | Newsletters                     | newsletters      |

|  3 | Cancel                          | cancel           |

|  4 |  Book consultation - Contact me | contact-me       |

|  5 | Reschedule                      | reschedule       |

|  6 | Book consultation - Existing    | contact-existing |

|  7 | Book consultation - Steps       | contact-steps    |

+----+---------------------------------+------------------+

7 rows in set (0.002 sec)
 
MySQL [craft_db]> SHOW TABLES LIKE 'craft_freeform_submissions_%';

+---------------------------------------------------+

| Tables_in_craft_db (craft_freeform_submissions_%) |

+---------------------------------------------------+

| craft_freeform_submissions_cancel_3               |

| craft_freeform_submissions_contact_1              |

| craft_freeform_submissions_contact_existing_6     |

| craft_freeform_submissions_contact_me_4           |

| craft_freeform_submissions_contact_steps_7        |

| craft_freeform_submissions_newsletters_2          |

| craft_freeform_submissions_reschedule_5           |

+---------------------------------------------------+

7 rows in set (0.003 sec)

How can we reproduce this?

  1. Upgrade Freeform from 4.1.28 to Freeform 5.X
  2. composer install
  3. php craft up

Freeform Edition

Pro

Freeform Version

4.1.28

Craft Version

4.16.15

When did this issue start?

  • Unsure
  • Fresh install of Freeform
  • After upgrading from older Freeform version
  • After upgrading from older Craft version
  • After a change to hosting configuration

Previous Freeform Version

4.1.28

Metadata

Metadata

Labels

investigatingCurrently investigating the report

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions