Davit
Davit

Reputation: 362

Symfony2 "php app/console doctrine:schema:update --force" doens't add a column to table

I am trying to add a column to a table through doctrine command:

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

I know it can do that, since I've done that before and documentation states that clearly:

"In other words, if you add a new property with mapping metadata to Product and run this task again, it will generate the "alter table" statement needed to add that new column to the existing product table."

The following is the field I'm trying to add as a column:

/**
 * @var string
 *
 * @ORM\Column(name="service_machine_name", type="string", length=40, nullable=false)
 */
private $serviceMachineName;

But when I type: php app/console doctrine:schema:update --force

It tells me that my database is in sync with my current entity, but it clearly is not, because I have an additional field in my entity class.

I also tried shortening the column name to 3 letters (just in case), but it still doesn't add a column!

Note: I have added columns to a different table on the same database (which is remote) and it worked fine before.

Upvotes: 1

Views: 7048

Answers (2)

juanitourquiza
juanitourquiza

Reputation: 2194

This answer is correct: https://stackoverflow.com/a/22198323/2400373

But don't work in symfony 3, for this version is necessary a change, the code is:

You have to first create setter and getter for that columns like this

php bin/console doctrine:generate:entities Acme/DemoBundle/Entity/User

after that you have to use

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

Upvotes: 0

Suresh Kumar Amrani
Suresh Kumar Amrani

Reputation: 935

You have to first create setter and getter for that columns like this

php app/console doctrine:generate:entities Acme/DemoBundle/Entity/User

after that you have to use

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

Upvotes: 4

Related Questions