Symfony2 command "doctrine:schema:update" not detect trait file changes used in entities

16,000

Solution 1

You can force this by doing:

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

Solution 2

May be I'm too late, but if you use memcache you need to clear memcache too. So you need to do something like:

echo 'flush_all' | nc yourhost 11211
php app/console cache:clear
php app/console doctrine:schema:update

Solution 3

Try to enable Doctrine auto mapping and remove this folder : YourBundle\Resources\config\doctrine

Solution 4

It is possible that you forget to enable Doctrine auto mapping;

orm:
        #auto_mapping: true

If auto mapping is disabled (or commented like above) , you should register Entiteis of each bundle manually.

orm:
       entity_managers:
                    default:
                        mappings:
                            AcmeHelloBundle: ~

Solution 5

Check your annotation before class declaration. Is there @ORM\Entity ? In my situation adding this line helps.

Share:
16,000
Admin
Author by

Admin

Updated on July 23, 2022

Comments

  • Admin
    Admin almost 2 years

    I have a Trait file with shared code between entities.

    trait file example:

    <?php
    namespace Acme\CmsBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    
    /**
    * BaseHtml Trait
    *
    */
    trait BaseHtml
    {
    
        /**
        * @var integer
        *
        * @ORM\Column(name="status", type="string", length=20)
        */
        private $status;
    
        /**
        * @var \DateTime
        *
        * @ORM\Column(name="date", type="datetime")
        */
        private $date;
    
        public function setStatus($status)
        {
            $this->status = $status;
    
            return $this;
        }
    
        public function getStatus()
        {
            return $this->status;
        }
    
        public function setDate($date)
        {
            $this->date = $date;
    
            return $this;
        }
    
        public function getDate()
        {
            return $this->date;
        }
    
    }
    

    Entity file example:

    <?php
    
    namespace Acme\CmsBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    
    /**
    * Page
    *
    * @ORM\Table()
    * @ORM\Entity
    * 
    * 
    */
    class Page
    {
    
        use BaseHtml;
    
    
        /**
        * @var integer
        *
        * @ORM\Column(name="id", type="integer")
        * @ORM\Id
        * @ORM\GeneratedValue(strategy="AUTO")
        */
        private $id;
    
        /**
        * @var string
        *
        * @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Gallery") 
        */
        private $gallery;
    
    
    
        public function getId()
        {
            return $this->id;
        }
    
    
        public function setGallery(\Application\Sonata\MediaBundle\Entity\Gallery $gallery)
        {
            $this->gallery = $gallery;
    
            return $this;
        }
    
    
        public function getGallery()
        {
            return $this->gallery;
        }
    }
    

    But when I modify the annotations of trait file or add new columns and execute "php app/console doctrine:schema:update":

    Nothing to update - your database is already in sync with the current entity metadata.
    

    I need change manually date modification of all entities files who use traits file for get doctrine:schema:update run properly.

    I tried with commands

    php app/console doctrine:cache:clear-metadata
    php app/console cache:clear
    

    before execute doctrine:schema:update, but without result.

    Any idea for don't manually update entities files and doctrine:schema:update detect updates of entities when change traits file, i lost part of advantages of sharing code with traits.

  • Admin
    Admin over 10 years
    I have updated symfony and all vendors and now clean metadata cache with that commands. Maybe some filesystem corruption ¿?. Thanks for the reply
  • Herr Nentu'
    Herr Nentu' about 9 years
    Or redis for that matter
  • Ryall
    Ryall about 8 years
    Shame but it seems Doctrine doesn't detect Trait changes as part of the cache update so this seems to be the simplest solution around it for now.
  • MakG
    MakG over 7 years
    Updating all vendors with composer update worked for me too. Strange.
  • Albeis
    Albeis about 7 years
    Herod is right. Smthg like redis-cli flushall and then update it.