craftcms / commerce

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

[5.x]: Upgrading from version 4 to version 5, multiple migrations failing #3496

Closed satanspropaganda closed 1 month ago

satanspropaganda commented 1 month ago

What happened?

Description

When upgrading, I keep hitting migrations that fail and break the whole upgrade process with the error message "Migration failed. The rest of the migrations are canceled."

`*** applying m221025_083940_add_purchasables_stores_table

add column width decimal(14,4) to table {{%commerce_purchasables}} ...Exception: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'width' The SQL being executed was: ALTER TABLE commerce_purchasables ADD width decimal(14,4) (/Users/bennybrown/Herd/update/vendor/yiisoft/yii2/db/Schema.php:676) *** applying m221122_055724_move_general_settings_to_per_store_settings add column autoSetNewCartAddresses boolean NOT NULL DEFAULT FALSE to table {{%commerce_stores}} ... done (time: 0.006s) add column autoSetCartShippingMethodOption boolean NOT NULL DEFAULT FALSE to table {{%commerce_stores}} ... done (time: 0.005s) add column autoSetPaymentSource boolean NOT NULL DEFAULT FALSE to table {{%commerce_stores}} ... done (time: 0.005s) add column autoSetPaymentSource boolean NOT NULL DEFAULT FALSE to table {{%commerce_stores}} ...Exception: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'autoSetPaymentSource' The SQL being executed was: ALTER TABLE commerce_stores ADD autoSetPaymentSource tinyint(1) NOT NULL DEFAULT FALSE (/Users/bennybrown/Herd/update/vendor/yiisoft/yii2/db/Schema.php:676)`

Steps to reproduce

  1. I am upgrading our site from Craft 4 to Craft 5, these errors occur when I run "php run craft/up"

Expected behavior

The migrations to run with no issues & the system to upgrade

Actual behavior

The whole upgrade to fail due to multiple migrations failing

Craft CMS version

5.1.3

Craft Commerce version

5.0.5

PHP version

8.3

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 1 month ago

PT-1726 [5.x]: Upgrading 4 - 5, migrations failing

lukeholder commented 1 month ago

Thanks, this is fixed for the next release.

Related: https://github.com/craftcms/commerce/pull/3495

To get the fix early, change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "5.x-dev#000d10999732d2e8574114249f840eff962382ec as 5.0.4",
  "...": "..."
}

Then run composer update. Restore your database and run the upgrade again.

We will update this issue with notification once the release is out.

satanspropaganda commented 1 month ago

Hey @lukeholder,

I've just tested this and unfortunately even with restoring the database and trying out the newer version of the plugin, we still get the exact same issue

`*** applying m221025_083940_add_purchasables_stores_table

add column width decimal(14,4) to table {{%commerce_purchasables}} ... done (time: 0.009s) add column height decimal(14,4) to table {{%commerce_purchasables}} ... done (time: 0.010s) add column length decimal(14,4) to table {{%commerce_purchasables}} ... done (time: 0.009s) add column weight decimal(14,4) to table {{%commerce_purchasables}} ... done (time: 0.010s) add column taxCategoryId integer to table {{%commerce_purchasables}} ... done (time: 0.010s) add column shippingCategoryId integer to table {{%commerce_purchasables}} ... done (time: 0.014s) add foreign key fk_lajeofrwubjmlrvluvzubooltqevokzddqyn: {{%commerce_purchasables}} (taxCategoryId) references {{%commerce_taxcategories}} (id) ... done (time: 0.874s) add foreign key fk_jkyhofxoothrrhjbcqdszwndhkyzaiwfewtt: {{%commerce_purchasables}} (shippingCategoryId) references {{%commerce_shippingcategories}} (id) ... done (time: 0.998s) create table {{%commerce_purchasables_stores}} ...Exception: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'commerce_purchasables_stores' already exists The SQL being executed was: CREATE TABLE commerce_purchasables_stores (`

Thanks

lukeholder commented 1 month ago

It looks like your database is not a Commerce 4 database if the commerce_purchasables_stores table exists in it before upgrade?

Can you restore your database and see if that table is in there? If it is, that is not a Commerce 4 DB backup.