无法在Symfony中为模型添加字段,bin / console崩溃

时间:2019-01-31 15:26:33

标签: symfony doctrine-orm sylius symfony-3.2

我正在使用Sylius框架。我正在关注guide to customize models

我试图将字段notice添加到模型Taxon中,该模型已经在我的项目中被覆盖。为此,我在模型的Taxon.orm.yml中添加了字段描述:

MyProject\Bundle\ShopBundle\Entity\Taxon:
    type: entity
    table: sylius_taxon

    # {Relationships code...}

    fields:
        # {Some existing fields...}

        notice:
            type: text
            nullable: true

我还向覆盖的Taxon类中添加了一个字段,一个getter和一个setter。

然后,我尝试运行bin/console doctrine:migrations:diff,但是即使没有任何参数,我也运行bin/console时,它崩溃,但出现以下异常:

[Doctrine\DBAL\Exception\InvalidFieldNameException]
  An exception occurred while executing 'SELECT s0_.code AS code_0, s0_.tree_left AS tree_left_1, s0_.tree_right AS tree_right_2, s0_.tree_level AS tree_level_3, s0_.position AS position_4, s0_.id AS id_5, s0_
  .created_at AS created_at_6, s0_.updated_at AS updated_at_7, s0_.enabled AS enabled_8, s0_.default_markup AS default_markup_9, s0_.notice AS notice_10, s0_.tree_root AS tree_root_11, s0_.parent_id AS parent_
  id_12 FROM sylius_taxon s0_ WHERE s0_.parent_id IS NULL ORDER BY s0_.tree_left ASC':
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 's0_.notice' in 'field list'`


[Doctrine\DBAL\Driver\PDOException]
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 's0_.notice' in 'field list'`


[PDOException]
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 's0_.notice' in 'field list'

如果我删除了对Taxon.orm.yml的更改,那么bin/console将再次起作用。我的更改缺少什么?

2 个答案:

答案 0 :(得分:1)

我的捆绑软件配置之一就是该模型的存储库。我暂时从config.yml删除了捆绑软件的配置,bin/console正常工作。

答案 1 :(得分:-1)

添加新字段时,您应该doctrine:schema:update