diff --git a/CHANGELOG.md b/CHANGELOG.md index de587a07de4..c931c3f9377 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Fixed a bug where system icons whose names ended in numbers weren’t displaying. ([#14740](https://github.com/craftcms/cms/issues/14740)) - Fixed an error that could occur when creating a passkey. ([#14745](https://github.com/craftcms/cms/issues/14745)) - Fixed a bug where the “Utilities” global nav item could get two badge counts. +- Fixed a bug where custom fields whose previous types were missing would lose their values when updating to Craft 5. ## 5.0.0 - 2024-03-26 diff --git a/src/migrations/BaseContentRefactorMigration.php b/src/migrations/BaseContentRefactorMigration.php index a5375700a3e..2cbf3845db7 100644 --- a/src/migrations/BaseContentRefactorMigration.php +++ b/src/migrations/BaseContentRefactorMigration.php @@ -8,6 +8,7 @@ use craft\db\Query; use craft\db\Table; use craft\fieldlayoutelements\CustomField; +use craft\fields\MissingField; use craft\helpers\ArrayHelper; use craft\helpers\Db; use craft\helpers\Json; @@ -118,7 +119,13 @@ protected function updateElements( foreach ($fieldColumns as $layoutElementUid => $column) { $field = $fieldsByUid[$layoutElementUid]; - $dbType = $field::dbType(); + + if ($field instanceof MissingField) { + // Figure it out from the actual DB column + $dbType = $contentTableSchema->getColumn($column)?->dbType; + } else { + $dbType = $field::dbType(); + } if (is_array($column)) { /** @var array $dbType */