Showing posts with label setter. Show all posts
Showing posts with label setter. Show all posts

Thursday, September 21, 2017

Symfony migrations

This short tutorial show how to migrate model and the database in Symfony.

Add property in AppBundle/Entity/User.php

/**
 * @ORM\Column(name="message", type="string", nullable=true)
 */
protected $message;

then in console

php bin/console doctrine:migrations:diff

this will generate file app/DoctrineMigrations/Version20170921225541.php
at this point you still don't have getter and setter for $message nor column message in table.

php bin/console doctrine:migrations:execute 20170921225541 --up

now you have message column in table, but not getter and setter for $message

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

this will create the getter and setter.

The reverse process is:

php bin/console doctrine:migrations:execute 20170921225541 --down

this reverts database table. Remove message property and it's getter and setter. And your code and database are in sync.