solspace / craft-freeform

Freeform for Craft: The most reliable form builder that's ready for wherever your project takes you.
https://docs.solspace.com/craft/freeform/v5/
Other
47 stars 61 forks source link

Failed Migration to Craft 4 - failed to apply m220330_111857_SplitSubmissionsTable #691

Closed matthaltuch closed 1 year ago

matthaltuch commented 1 year ago

Describe the bug or issue you're experiencing

I am trying to upgrade from craft 3 to craft 4, through that process when the update starts to run through the database migrations it fails at the same point (I have tried this several times with a clean version of a production DB) - I had contacted craft support originally and their inclination was that this is more of a Freeform issue vs a craft related one.

It looks like the migration is trying to create a table that already exists or was created earlier in the migration process.

Any info you may be able to help with this issue is greatly appreciated

Portion of the terminal output from a failed upgrade attempt:

craft_1 | > create table {{%freeform_submissions_contact_us_1}} ...Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'freeform_submissions_contact_us_1' already exists craft_1 | The SQL being executed was: CREATE TABLE freeform_submissions_contact_us_1 ( craft_1 | id int(11) NOT NULL, craft_1 | first_name_1 text, craft_1 | last_name_2 text, craft_1 | phone_15 text, craft_1 | email_3 text, craft_1 | card_number_or_username_16 text, craft_1 | message_12 text, craft_1 | subject_17 text, craft_1 | board_of_trustees_48 text, craft_1 | executive_director_47 text, craft_1 | branch_services_director1_51 text, craft_1 | branch_services_director2_52 text, craft_1 | branch_services_director3_53 text, craft_1 | branch_locations_dynamic_45 text craft_1 | ) ENGINE = InnoDb DEFAULT CHARACTER SET = utf8 (/var/www/src/vendor/yiisoft/yii2/db/Schema.php:676) craft_1 | #0 /var/www/src/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'CREATE TABLE f...') craft_1 | #1 /var/www/src/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute('CREATE TABLEf...') craft_1 | #2 /var/www/src/vendor/yiisoft/yii2/db/Migration.php(322): yii\db\Command->execute() craft_1 | #3 /var/www/src/vendor/solspace/craft-freeform/packages/plugin/src/migrations/m220330_111857_SplitSubmissionsTable.php(118): yii\db\Migration->createTable('{{%freeform_sub...', Array) craft_1 | #4 /var/www/src/vendor/solspace/craft-freeform/packages/plugin/src/migrations/m220330_111857_SplitSubmissionsTable.php(85): Solspace\Freeform\migrations\m220330_111857_SplitSubmissionsTable->createFormTable(1, 'contact_us', Array) craft_1 | #5 /var/www/src/vendor/craftcms/cms/src/db/Migration.php(49): Solspace\Freeform\migrations\m220330_111857_SplitSubmissionsTable->safeUp() craft_1 | #6 /var/www/src/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(758): craft\db\Migration->up() craft_1 | #7 /var/www/src/vendor/craftcms/cms/src/console/controllers/MigrateController.php(358): yii\console\controllers\BaseMigrateController->migrateUp('m220330111857...') craft_1 | #8 [internal function]: craft\console\controllers\MigrateController->actionAll() craft_1 | #9 /var/www/src/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array) craft_1 | #10 /var/www/src/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array) craft_1 | #11 /var/www/src/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('all', Array) craft_1 | #12 /var/www/src/vendor/craftcms/cms/src/console/ControllerTrait.php(87): yii\console\Controller->runAction('all', Array) craft_1 | #13 /var/www/src/vendor/yiisoft/yii2/base/Module.php(552): craft\console\controllers\MigrateController->runAction('all', Array) craft_1 | #14 /var/www/src/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array) craft_1 | #15 /var/www/src/vendor/craftcms/cms/src/console/Application.php(90): yii\console\Application->runAction('migrate/all', Array) craft_1 | #16 /var/www/src/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/all', Array) craft_1 | #17 /var/www/src/vendor/craftcms/cms/src/console/Application.php(121): yii\console\Application->handleRequest(Object(craft\console\Request)) craft_1 | #18 /var/www/src/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request)) craft_1 | #19 /var/www/src/craft(22): yii\base\Application->run() craft_1 | #20 {main} craft_1 | *** failed to apply m220330_111857_SplitSubmissionsTable (time: 0.005s) craft_1 | craft_1 | craft_1 | 37 from 54 migrations were applied. craft_1 | craft_1 | Migration failed. The rest of the migrations are canceled. ccpl-craft3_craft_1 exited with code 1

Craft & Plugin Info (please complete the following information):

Additional context

kjmartens commented 1 year ago

Sorry for the trouble @matthaltuch.

Just to confirm, you're saying that the freeform_submissions_contact_us_1 table already exists on your Craft 3 site? If so, this should not be the case, as individual submission database tables per form did not exist until Freeform 4 for Craft 4.

My best guess (without knowing any other context at this time) is that the migration was attempted and failed (at least partially), and it created the freeform_submissions_contact_us_1 table (and possibly others, but is erroring on the first form's table). Can you see if you have any older backups of the database? You might be able to just manually delete this submission table (and others) - and try again, but I'm not sure how much of the Freeform 4 migration has run. πŸ™‚

matthaltuch commented 1 year ago

Hi @kjmartens

I have verified that prior to any updates/migrations being done that there are no additional freeform tables in the DB, this is pulled from a production environment that has not been updated to craft 4 yet and is still running craft 3. There are no migrated tables at the start of this attempted update

When doing the update, the process runs ... creates the "freeform_submissions_contact_us_1" table (which i can see added as a DB table after the failed update) but the process fails at the same point when trying to apply the freeform "m220330_111857_SplitSubmissionsTable"

craft_1 | > update in {{%freeform_submissions}} ... done (time: 0.002s) craft_1 | > update in {{%freeform_submissions}} ... done (time: 0.001s) craft_1 | > update in {{%freeform_submissions}} ... done (time: 0.001s) craft_1 | > update in {{%freeform_submissions}} ... done (time: 0.002s) craft_1 | > update in {{%freeform_submissions}} ... done (time: 0.001s) craft_1 | > update in {{%freeform_submissions}} ... done (time: 0.001s) craft_1 | *** applied m220323_113852_MigrateEmailValuesToString (time: 4.600s) craft_1 | craft_1 | *** applying m220330_111857_SplitSubmissionsTable craft_1 | > create table {{%freeform_submissions_contact_us_1}} ...Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'freeform_submissions_contact_us_1' already exists craft_1 | The SQL being executed was: CREATE TABLEfreeform_submissions_contact_us_1( craft_1 |idint(11) NOT NULL, craft_1 |first_name_1text, craft_1 |last_name_2text, craft_1 |phone_15text, craft_1 |email_3text, craft_1 |card_number_or_username_16text, craft_1 |message_12text, craft_1 |subject_17text, craft_1 |board_of_trustees_48text, craft_1 |executive_director_47text, craft_1 |branch_services_director1_51text, craft_1 |branch_services_director2_52text, craft_1 |branch_services_director3_53text, craft_1 |branch_locations_dynamic_45text craft_1 | ) ENGINE = InnoDb DEFAULT CHARACTER SET = utf8 (/var/www/src/vendor/yiisoft/yii2/db/Schema.php:676) craft_1 | #0 /var/www/src/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'CREATE TABLEf...') craft_1 | #1 /var/www/src/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute('CREATE TABLE f...') craft_1 | #2 /var/www/src/vendor/yiisoft/yii2/db/Migration.php(322): yii\db\Command->execute() craft_1 | #3 /var/www/src/vendor/solspace/craft-freeform/packages/plugin/src/migrations/m220330_111857_SplitSubmissionsTable.php(118): yii\db\Migration->createTable('{{%freeform_sub...', Array) craft_1 | #4 /var/www/src/vendor/solspace/craft-freeform/packages/plugin/src/migrations/m220330_111857_SplitSubmissionsTable.php(85): Solspace\Freeform\migrations\m220330_111857_SplitSubmissionsTable->createFormTable(1, 'contact_us', Array) craft_1 | #5 /var/www/src/vendor/craftcms/cms/src/db/Migration.php(49): Solspace\Freeform\migrations\m220330_111857_SplitSubmissionsTable->safeUp() craft_1 | #6 /var/www/src/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(758): craft\db\Migration->up() craft_1 | #7 /var/www/src/vendor/craftcms/cms/src/console/controllers/MigrateController.php(358): yii\console\controllers\BaseMigrateController->migrateUp('m220330_111857_...') craft_1 | #8 [internal function]: craft\console\controllers\MigrateController->actionAll() craft_1 | #9 /var/www/src/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array) craft_1 | #10 /var/www/src/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array) craft_1 | #11 /var/www/src/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('all', Array) craft_1 | #12 /var/www/src/vendor/craftcms/cms/src/console/ControllerTrait.php(87): yii\console\Controller->runAction('all', Array) craft_1 | #13 /var/www/src/vendor/yiisoft/yii2/base/Module.php(552): craft\console\controllers\MigrateController->runAction('all', Array) craft_1 | #14 /var/www/src/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array) craft_1 | #15 /var/www/src/vendor/craftcms/cms/src/console/Application.php(90): yii\console\Application->runAction('migrate/all', Array) craft_1 | #16 /var/www/src/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/all', Array) craft_1 | #17 /var/www/src/vendor/craftcms/cms/src/console/Application.php(121): yii\console\Application->handleRequest(Object(craft\console\Request)) craft_1 | #18 /var/www/src/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request)) craft_1 | #19 /var/www/src/craft(22): yii\base\Application->run() craft_1 | #20 {main} craft_1 | *** failed to apply m220330_111857_SplitSubmissionsTable (time: 0.007s) craft_1 | craft_1 | craft_1 | 37 from 54 migrations were applied. craft_1 | craft_1 | Migration failed. The rest of the migrations are canceled. ccpl-craft3_craft_1 exited with code 1

Its like the update is creating the table, then trying to create it again for some reason.

Is there something within the update that may be duplicating this table creation? I cleared out all of the data from the submission table as well to rule out any odd characters in a submission causing an issue and with no submissions (removed from the craft CP) that this fails at the same point.

Please let me know if there any additional info that you may need to help resolve this issue - thanks, M

williamhibberd commented 1 year ago

I am having the same issue with my attempt to upgrade to craft v4

kjmartens commented 1 year ago

Hi @williamhibberd,

I was able to resolve this issue with @matthaltuch by setting up their site locally and running the upgrade and migration myself. I did clean up some things before proceeding, so I'm not sure exactly why it didn't work before, but here are some possibilities to watch out for:

Is it possible either of these may apply in your install? πŸ™‚