Symfony 3, Add A New Column To Database Table Using Doctrine Command


Modify you metadata file with new column name that you are going to add/modify. For example i have a user table metadata file and want to add a phone column. The metadata file is in yml format. Metadata files are found under the following path


src/AppBundle/Resources/config/doctrine

lets open the file that you want to modify and add the following lines:


phone:
    type: string
    nullable: true
    length: 255
    options:
        fixed: false    

Now Run the following doctrine command to update your Entity class based on the changes at your metadata file. Here i am updating only my Users Entity Class.



php bin/console doctrine:generate:entities AppBundle:Users


Now run the following doctrine command to update your database table with the modification you have done yet.



php bin/console doctrine:schema:update --force


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s