How To Add a Column To an Existing Entity in Symfony?

As you want to keep your customers/peers updated with the latest version of the model, you should use the Doctrine Migrations. That's the way to manage database updates. Moreover, it gives you complete control on what to do when upgrading/downgrading the database.

The steps for adding a new property/column on the entity class are:

1. Add the property you want eg. On User Entity class
    UserBundle\Entity\User

2. Run the following console command 
    php app/console doctrine:generate:entities UserBundle:User

- It will add the proper getter/setter in the entity class.

3. Run the following console command  
    php app/console doctrine:migrations:diff

- It will generate a migration by comparing your current database to your mapping information and place a new migration file on app/Migrations/.

4. Run the following console command 
    php app/console doctrine:migrations:migrate

- It will execute a migration to a specified version or the latest available version.

Source: http://stackoverflow.com/a/14942242

Comments

Popular Posts