从Shopware5迁移至Shopware6时日志出现SWAG_MIGRATION_RUN_EXCEPTION异常求助
Shopware 5.7 迁移至 6.4.13 数据未显示且类型错误问题
环境信息
- PHP版本:8.1
- Shopware版本:6.4.13
- 迁移场景:Shopware 5.7(带演示数据)→ Shopware 6.4.13(本地虚拟环境)
- 操作:已按官方迁移流程执行,使用本地网关配置
问题现象
迁移状态显示“成功”,但Shopware 6后台及前端无迁移数据,迁移日志存在类型不兼容错误:
[error] SWAG_MIGRATION_RUN_EXCEPTION An exception occurred Entity: language, sourceId: - SwagMigrationAssistant\Migration\Logging\Log\ExceptionRunLog::__construct(): Argument #4 ($sourceId) must be of type ?string, int given, called in /var/www/webdev/shopware56/custom/plugins/SwagMigrationAssistant/Migration/Service/MigrationDataConverter.php on line 144 [error] SWAG_MIGRATION_RUN_EXCEPTION An exception occurred Entity: category, sourceId: - SwagMigrationAssistant\Profile\Shopware\Converter\ShopwareConverter::getSourceIdentifier(): Return value must be of type string, int returned [error] SWAG_MIGRATION_RUN_EXCEPTION An exception occurred Entity: customer_group, sourceId: - SwagMigrationAssistant\Profile\Shopware\Converter\ShopwareConverter::getSourceIdentifier(): Return value must be of type string, int returned [error] SWAG_MIGRATION_RUN_EXCEPTION An exception occurred Entity: sales_channel, sourceId: - SwagMigrationAssistant\Profile\Shopware\Converter\ShopwareConverter::getSourceIdentifier(): Return value must be of type string, int returned
解决方案
1. 匹配迁移助手插件版本
Shopware 6.4.13 与高版本SwagMigrationAssistant存在PHP 8.1类型兼容性问题,需安装与Shopware 6.4.x严格匹配的插件版本(推荐SwagMigrationAssistant 3.4.x系列,对应Shopware minor版本号)。
2. 临时修复类型转换问题(仅调试用,优先升级插件)
- 修改
/var/www/webdev/shopware56/custom/plugins/SwagMigrationAssistant/Migration/Service/MigrationDataConverter.php第144行,将$sourceId强制转为字符串:// 原代码 $log = new ExceptionRunLog($runId, $entity, $sourceId, $exception); // 修改后 $log = new ExceptionRunLog($runId, $entity, (string)$sourceId, $exception); - 修改
SwagMigrationAssistant/Profile/Shopware/Converter/ShopwareConverter.php的getSourceIdentifier方法,确保返回字符串类型:public function getSourceIdentifier(): string { return (string)$this->source['id']; }
3. 重置迁移流程
- 在Shopware 6后台删除当前迁移任务,清空迁移日志
- 重新创建迁移连接,执行全量迁移
- 迁移完成后清除缓存:
bin/console cache:clear bin/console cache:warmup
4. 检查源数据ID格式
确认Shopware 5中language、category等实体的ID为标准整数类型,避免自定义场景下的非标准ID导致转换失败。
内容的提问来源于stack exchange,提问作者Softound Solutions
相关产品推荐
相关产品推荐

