craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
226 stars 170 forks source link

[5.2.4]: Failed migration when upgrading from Craft 4 and commerce 4 #3778

Open mariuswestgaard opened 2 hours ago

mariuswestgaard commented 2 hours ago

What happened?

Description

I'm having issue upgrading from latest Craft Commerce 4 and latest Craft 4 to latest commerce (5.2.4) and craft version (5.5.2). When deploying the updated files, and after successfully running composer install, I get an error in one of the migrations when running php craft up. Any tips on how to fix this issue?

Error:

*** applying m240308_133451_tidy_shipping_categories
    > delete from {{%commerce_shippingcategories}} ... done (time: 0.012s)
    > dropping foreign key on {{%commerce_shippingcategories}} if it exists ... done (time: 0.048s)
    > add foreign key craft_fk_pdmmspmvjfldsseqavbcwrcgioqvlqncntzf: {{%commerce_shippingcategories}} (storeId) references {{%commerce_stores}} (id) ... done (time: 0.110s)
    > alter column storeId in table {{%commerce_shippingcategories}} to integer NOT NULL ...Exception: SQLSTATE[HY000]: General error: 1832 Cannot change column 'storeId': used in a foreign key constraint 'craft_fk_pdmmspmvjfldsseqavbcwrcgioqvlqncntzf'
The SQL being executed was: ALTER TABLE `craft_commerce_shippingcategories` CHANGE `storeId` `storeId` int(11) NOT NULL (/srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/db/Schema.php:676)
#0 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/db/Command.php(1325): yii\db\Schema->convertException(Object(PDOException), 'ALTER TABLE `cr...')
#1 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/db/Command.php(1120): yii\db\Command->internalExecute('ALTER TABLE `cr...')
#2 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/db/Migration.php(431): yii\db\Command->execute()
#3 /srv/app/nortek-staging/htdocs/vendor/craftcms/commerce/src/migrations/m240308_133451_tidy_shipping_categories.php(30): yii\db\Migration->alterColumn('{{%commerce_shi...', 'storeId', Object(craft\db\mysql\ColumnSchemaBuilder))
#4 /srv/app/nortek-staging/htdocs/vendor/craftcms/cms/src/db/Migration.php(50): craft\commerce\migrations\m240308_133451_tidy_shipping_categories->safeUp()
#5 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(758): craft\db\Migration->up()
#6 /srv/app/nortek-staging/htdocs/vendor/craftcms/cms/src/console/controllers/MigrateController.php(382): yii\console\controllers\BaseMigrateController->migrateUp('m240308_133451_...')
#7 [internal function]: craft\console\controllers\MigrateController->actionAll()
#8 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#10 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('all', Array)
#11 /srv/app/nortek-staging/htdocs/vendor/craftcms/cms/src/console/controllers/MigrateController.php(195): yii\console\Controller->runAction('all', Array)
#12 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/base/Module.php(552): craft\console\controllers\MigrateController->runAction('all', Array)
#13 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#14 /srv/app/nortek-staging/htdocs/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('migrate/all', Array)
#15 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/base/Controller.php(212): craft\console\Application->runAction('migrate/all', Array)
#16 /srv/app/nortek-staging/htdocs/vendor/craftcms/cms/src/console/Controller.php(207): yii\base\Controller->run('migrate/all', Array)
#17 /srv/app/nortek-staging/htdocs/vendor/craftcms/cms/src/console/controllers/UpController.php(60): craft\console\Controller->run('migrate/all', Array)
#18 [internal function]: craft\console\controllers\UpController->actionIndex()
#19 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#20 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#21 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('', Array)
#22 /srv/app/nortek-staging/htdocs/vendor/craftcms/cms/src/console/ControllerTrait.php(88): yii\console\Controller->runAction('', Array)
#23 /srv/app/nortek-staging/htdocs/vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction('', Array)
#24 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('', Array)
#25 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('up', Array)
#26 /srv/app/nortek-staging/htdocs/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('up', Array)
#27 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('up', Array)
#28 /srv/app/nortek-staging/htdocs/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#29 /srv/app/nortek-staging/htdocs/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#30 /srv/app/nortek-staging/htdocs/craft(11): yii\base\Application->run()
#31 {main}

Steps to reproduce

  1. Have latest Craft 4 and commerce installed
  2. Follow the update guides on craft and commerce
  3. Push changes to server
  4. Run composer install to have latest packages
  5. Run php craft up to run migrations and all

Expected behavior

I'd expect the migrations to run successfully.

Actual behavior

The m240308_133451_tidy_shipping_categories migration fails.

Craft CMS version

5.5.2

Craft Commerce version

5.2.4

PHP version

8.2

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

linear[bot] commented 2 hours ago

PT-2319 [5.2.4]: Failed migration when upgrading from Craft 4 and commerce 4