You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OroPlatform执行迁移时报attachmentExtension为null的问题解决

OroCommerce为oro_brand添加Image属性迁移报错处理

我需要给oro_brand添加Image属性,参考官方配置文档完成代码开发后,执行迁移命令时出现报错。

报错信息

执行bin/console oro:migration:load --force -vvv时抛出如下错误:

Process migrations...
  > Oro\Bundle\EntityExtendBundle\Migration\LoadEntityConfigStateMigration
  > Test\Bundle\BrandBundle\Migrations\Schema\TestBrandBundleInstaller

In AddLogoToBrand.php line 42:
                                                           
  [Symfony\Component\Debug\Exception\FatalThrowableError]  
  Call to a member function addImageRelation() on null  

报错显示$this->attachmentExtension值为null,但代码写法完全遵循官方规范和已有厂商实现示例,相关代码如下:

//src/Test/Bundle/BrandBundle/Migrations/Schema/v1_0/AddLogoToBrand.php

use Doctrine\DBAL\Schema\Schema;
use Oro\Bundle\AttachmentBundle\Migration\Extension\AttachmentExtensionAwareInterface;
use Oro\Bundle\AttachmentBundle\Migration\Extension\AttachmentExtensionAwareTrait;
use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;
use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\MigrationBundle\Migration\OrderedMigrationInterface;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

class AddLogoToBrand implements Migration, OrderedMigrationInterface, AttachmentExtensionAwareInterface
{
    use AttachmentExtensionAwareTrait;

    public const LOGO_SIZE = 10;
    public const BRAND_TABLE = 'oro_brand';
    public const FIELD_NAME = 'logo';

    /**
     * {@inheritdoc}
     */
    public function getOrder(): int
    {
        return 10;
    }

    /**
     * {@inheritdoc}
     */
    public function up(Schema $schema, QueryBag $queries): void
    {
        $this->addLogoBrandAssociation($schema);
    }

    /**
     * @param Schema $schema
     */
    public function addLogoBrandAssociation(Schema $schema)
    {
        $this->attachmentExtension->addImageRelation(
            $schema,
            self::BRAND_TABLE,
            self::FIELD_NAME,
            [
                'extend' => ['owner' => ExtendScope::OWNER_CUSTOM]
            ],
        );
    }

解决方案

删除自定义的TestBrandBundleInstaller后,迁移命令即可正常运行。


内容的提问来源于stack exchange,提问作者InCatIBelieve

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 10:45:07