Symfony2命令"doctrine:schema:update"不检测实体中使用的特征文件更改

Rav*_*avz 9 php doctrine traits symfony doctrine-orm

我有一个Trait文件,实体之间有共享代码.

特质文件示例:

<?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;
    }

}
Run Code Online (Sandbox Code Playgroud)

实体文件示例:

<?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;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我修改特征文件的注释或添加新列并执行"php app/console doctrine:schema:update"时:

Nothing to update - your database is already in sync with the current entity metadata.
Run Code Online (Sandbox Code Playgroud)

我需要手动更改所有实体文件的日期修改,使用traits文件获取doctrine:schema:update运行正常.

我尝试了命令

php app/console doctrine:cache:clear-metadata
php app/console cache:clear
Run Code Online (Sandbox Code Playgroud)

在执行doctrine:schema:update之前,但没有结果.

任何想法都不要手动更新实体文件和学说:架构:更新检测实体的更新时更改特征文件,我失去了与特征共享代码的部分优势.

Dim*_*ilo 8

可能我太迟了,但是如果你使用memcache,你也需要清除memcache.所以你需要做类似的事情:

echo 'flush_all' | nc yourhost 11211
php app/console cache:clear
php app/console doctrine:schema:update
Run Code Online (Sandbox Code Playgroud)


小智 6

您可以执行以下操作来强制执

php app/console cache:clear
php app/console doctrine:schema:update --force
Run Code Online (Sandbox Code Playgroud)


FAR*_*LOU 6

尝试启用Doctrine自动映射并删除此文件夹:YourBundle\Resources\config\doctrine