Can't add a field to a model in Symfony, bin/console crashes

586 Views Asked by At

I'm working with Sylius framework. I'm following the guide to customize models.

I am trying to add a field notice to a model Taxon which is already overridden in my project. For that, I added the field description to Taxon.orm.yml of the model:

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

    # {Relationships code...}

    fields:
        # {Some existing fields...}

        notice:
            type: text
            nullable: true

I also added a field, a getter and a setter to the overriding Taxon class.

Then I'm trying to run bin/console doctrine:migrations:diff, but when I run bin/console even without any arguments, it crashes with the following exception:

[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'

If I remove the changes to Taxon.orm.yml then bin/console works again. What is missing in my changes?

2

There are 2 best solutions below

0
gvlasov On BEST ANSWER

One of my bundles' configruation contained that model's repository, that's it. I temporarily deleted the bundle's configuration from config.yml, and bin/console worked.

4
Alexander Dimitrov On

When you add new field you should doctrine:schema:update