Add a column to an existing entity in Symfony

前端 未结 9 1838
误落风尘
误落风尘 2020-12-22 21:27

I\'ve been playing around with Symfony on my web server and I\'ve been creating entity with doctrine for my database. I wanted to add a column to one of these entity... I wa

相关标签:
9条回答
  • 2020-12-22 21:59

    You definitely DO want to open the PHP/XML/YML file where your entity is defined and add the column there. Then, you use the commandline and say

    console doctrine:schema:update
    

    That way, your entity definitions are in sync with the database and your database gets updated.

    0 讨论(0)
  • 2020-12-22 21:59

    Add new Column in Existing entity on Symfony. I have the same problem are there . after I long research best solutions are there.

    solution work on Symfony 4

    Example:

    Blog entity already created inside one name column are there and I want to add description column. so simple enter

    php bin/console make:entity Blog
    

    After run this command you want to add new column

    0 讨论(0)
  • 2020-12-22 22:02

    That's how it worked for me:

    • add new vars, setters and getters inside the existing class:
        src-->AppBundle-->Entity-->YourClassName.php
    
    • update the ORM File:
      src-->AppBundle-->Resources-->config-->doctrine-->YourClassName.orm.yml
    
    • run bash command:
      php bin/console doctrine:schema:update --force
    
    0 讨论(0)
提交回复
热议问题