1
votes

First off, I am completely new to Symfony2.

I created an entity -> created a table based on that entity -> created a form using the entity.

I have now realised I need to add a field to the form. So I did the following:

Added the new property -> Added the ORM annotations -> Generated the setters and getters -> ran "php app/console doctrine:schema:update"

This resulted in the following exception: "The table with name 'XXX' already exists"

So nothing was updated. Any idea what I did wrong? Below is the property I added to the entity:

/**
 * @var text
 *
 * @ORM\Column(name="description", type="text")
 *
 * @Assert\NotBlank(message="Please insert a description")
 * @Assert\Length(max=100)
 *
 */
private $description;
2
I have also tried this: stackoverflow.com/questions/14941358/… but that did not work eitherDeveloper1
what do you have inside of @ORM\Table() in your class annotations?Dheeraj
Are you sure you ran php app/console doctrine:schema:update? Firstly, you would need the flag php app/console doctrine:schema:update --force to actually run that command. Secondly, the exception you encountered sounds more like something you get when running php app/console doctrine:schema:create on an existing schema; e.g SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'my_table' already exists.Darragh Enright
Yes sorry I have should have said I used the --force flag. and yes I did run that command.Developer1
And why the drive by down vote? Seems like a perfectly reasonable question to me. Wish down voters would grow a pair and indicate why they do things.Cerad

2 Answers

2
votes

Try using Doctrine Migrations Bundle. What you are trying to do - make changes to a database you've already deployed - is called a "database migration." I've found this bundle to be very helpful.

Instead of running "app/console doctrine:schema:update", you'll run "app/console doctrine:migrations:diff" which will compare your database schema against your updated entity and generate the sql code to bring them back in sync.

0
votes

I know this is an old question. But I write because it can be usefull for others.

Probably you are not using annotations in your project. Probably your project is confiured for use xml or yml.

you must to check your configuation at $proyect_home/app/config/config.yml and write in the orm zone:

orm:
  ....
  mappings:
    AppBundle:
      type: annotation