3

I try to add a cahmps in entity. I have this code:

/**
* @var integer $colorevent
* @ORM\Column(name="colorevent", type="integer")
*/
private $colorevent;

/**
* Get colorevent
* @return integer 
*/ 
public function getColorevent()
{
    return $this->colorevent;
}

/**
* Set colorevent
* @return integer 
*/
public function setColorevent($colorevent)
{
    return $this->colorevent = $colorevent ;
}

I run these commands:

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

which renders this message:

Nothing to update yopur database is already in sync with the current entity metadata

How do I add a field in entity?

3 Answers 3

2

How did you generated the entity class in the first time?

It the entity file was generated via doctrine:generate:entities then what you need to do is:

  1. update the Resources/config/doctrine/XXXXXXXXX where xxxx is the entity name.
  2. run app/console doctrine:generate:entity. This will regenerate the php entity file, and the private property, getter and setter.
  3. run php app/console doctrine:schema:update and update the DB

There may be some changes depending of the format you are using (I'm using yml) but the bottom line is that the doctrine:schema:update needs to find changes between the current and the cached (metadata) entity objects.

Sign up to request clarification or add additional context in comments.

1 Comment

I gave this a try, but I too couldn't get this to work. Essentially it just doesn't pick up the changes done to the Entity. (eg: change a column in the db to allow nullable fields, still renders a "nothing has changed" screen)
1

Each entity must have the Entity annotation

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class MyEntity
{
    // some code
}

I would also suggest using the console tools provided to create the entities.

app/console doctrine:generate:entity

For more information please read the official book (Doctrine, Propel).

1 Comment

Yes I try but it's the same probleme
0

If you're using yaml or annotations as described in the other two answers you can use the doctrine command. However the command must contain the entity name:

php app/console doctrine:generate:entities AcmeMyBundle:Customer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.