craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

[4.x]: Migrating 3.7.43 to 4.2.3 'sortOrder' cannot be null #11843

Closed Wiejeben closed 2 years ago

Wiejeben commented 2 years ago

What happened?

Description

Upgrading my Craft 3 site fails because in the old Craft matrixblocks table sortOrder was nullable and contained null values.

To make sure it wasn't a 3.7.43 issue I did update to 3.7.53.1 before going to 4, however that did not make a difference.

Steps to reproduce

  1. Have a Craft 3.7.43 install with matrixblocks where sortOrder is null
  2. Migrate to Craft 4.2.3

Expected behavior

Migrate successfully.

Actual behavior

*** applying m220213_015220_matrixblocks_owners_table
    > dropping {{%matrixblocks_owners}} if it exists ... done (time: 0.001s)
    > create table {{%matrixblocks_owners}} ... done (time: 0.004s)
    > add foreign key fk_rnxmtowmkvlvfzldckjgsoxxiowoppkfyjty: {{%matrixblocks_owners}} (blockId) references {{%matrixblocks}} (id) ... done (time: 0.009s)
    > add foreign key fk_rsowucrlagsuqmmabmtxrfjjjyhdwwfbujci: {{%matrixblocks_owners}} (ownerId) references {{%elements}} (id) ... done (time: 0.014s)
    > execute SQL: INSERT INTO {{%matrixblocks_owners}} ([[blockId]], [[ownerId]], [[sortOrder]]) 
SELECT [[id]], [[ownerId]], [[sortOrder]] 
FROM {{%matrixblocks}} ...Exception: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'sortOrder' cannot be null
The SQL being executed was: INSERT INTO `matrixblocks_owners` (`blockId`, `ownerId`, `sortOrder`) 
SELECT `id`, `ownerId`, `sortOrder` 
FROM `matrixblocks` (/var/www/vendor/yiisoft/yii2/db/Schema.php:676)
#0 /var/www/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException()
#1 /var/www/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute()
#2 /var/www/vendor/yiisoft/yii2/db/Migration.php(219): yii\db\Command->execute()
...
*** failed to apply m220213_015220_matrixblocks_owners_table (time: 0.058s)

12 from 23 migrations were applied.

Migration failed. The rest of the migrations are canceled.

Craft CMS version

4.2.3

PHP version

8.1.7

Operating system and version

Docker Alpine PHP FPM

Database type and version

MySQL 8.0.29

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.0-16)

Installed plugins and versions

brandonkelly commented 2 years ago

Thanks for reporting! Fixed for the next release.

brandonkelly commented 2 years ago

Craft 4.2.4 is tagged with that fix.