Doctrine 2.5: Unrecognized field (but only in Symfony's prod mode)

拥有回忆 提交于 2020-05-15 07:19:31

问题


So I seem to be plagued by issues that only affect production mode in Symfony and not developer mode. This time, I have a ManyToOne association and I'm trying to fetch only the entities which do not have an association (i.e. they have a NULL value in the database). This works exactly as I'd expect in dev move, but in prod mode, Doctrine throws an "unrecognized field" exception... for a field which absolutely does exist.

Here's the relevant part of the entity in question (Page.php):

/**
 * @ORM\ManyToOne(targetEntity="Project", inversedBy="pages")
 * @ORM\JoinColumn(name="project_id", referencedColumnName="ID")
 */
protected $project;

And here is the relevant line from the controller (PageController.php):

$pages = $this->getDoctrine()->getRepository('JCScopingBundle:Page')->findBy(['project' => null]);

Again, this works perfectly using app_dev.php (i.e. dev mode), but using app.php (i.e. prod mode) I keep getting the "unrecognized field" exception. What gives?

Update: I added a "weight" integer field to the same entity and that field is not recognized in prod mode either. This means I can't use prod mode, which means I can't upload my changes to the remote server. Really in a pickle here...


回答1:


In my case I forgot to restart 'memcached' service.

Check metadata_cache_driver type. In my case:

doctrine:
    orm:
        metadata_cache_driver:
            type: memcached
            host: localhost
            port: 11211
            instance_class: Memcached

Because previous metadata was cached, after applying migration, doctrine used that old cached metadata, without knowing about added new field.




回答2:


Well, low and behold, restarting the Apache service resolved the issue. Apparently that's the only way to truly clear the APCu metadata cache. I was inspired to try this based on this question/answer: Doctrine mapped field is not working



来源:https://stackoverflow.com/questions/47105977/doctrine-2-5-unrecognized-field-but-only-in-symfonys-prod-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!