I'm developing web site with Symfony 4.4, using SonataAdmin (^3.56), Doctrine ORM Admin (^3.12), Sonata Media (^3.22) and SonataClassification (^3.9) bundles. My web site works perfectly in dev mode. Problem is when I change it to prod mode.
.env
APP_ENV=prod
APP_DEBUG=0
When I access routes with SonataMedia gallery then I get error 500. Log file (prod.log) contains the following content:
request.CRITICAL: Uncaught PHP Exception Doctrine\ORM\ORMException: "Unrecognized field: gallery" at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php line 101 {"exception":"[object] (Doctrine\\ORM\\ORMException(code: 0): Unrecognized field: gallery at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php:101)"} []
In Controller I have:
...
$medias = $this->getDoctrine()->getRepository("ApplicationSonataMediaBundle:GalleryHasMedia")->findBy(array('gallery' => $article->getGallery()));
...
If i dump $medias in dev mode, it looks OK, with all images in gallery, but in production mode it doesn't work.
A similar thing happens in SonataAdmin Admin->Classification
request.CRITICAL: Uncaught PHP Exception Doctrine\ORM\Query\QueryException: "[Semantical Error] line 0, col 84 near 'parent IS NU': Error: Class App\Application\Sonata\ClassificationBundle\Entity\Category has no field or association named parent" at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php line 65 {"exception":"[object] (Doctrine\\ORM\\Query\\QueryException(code: 0): [Semantical Error] line 0, col 84 near 'parent IS NU': Error: Class App\\Application\\Sonata\\ClassificationBundle\\Entity\\Category has no field or association named parent at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php:65, Doctrine\\ORM\\Query\\QueryException(code: 0): SELECT c FROM App\\Application\\Sonata\\ClassificationBundle\\Entity\\Category c WHERE c.parent IS NULL at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php:43)"} []
and Tags, Collections, Media. Only Contexts is working normal. Gallery for example looks like:
config/packages/prod/doctrine.yaml
doctrine:
orm:
auto_generate_proxy_classes: false
metadata_cache_driver:
type: service
id: doctrine.system_cache_provider
query_cache_driver:
type: service
id: doctrine.system_cache_provider
result_cache_driver:
type: service
id: doctrine.result_cache_provider
services:
doctrine.result_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '@doctrine.result_cache_pool'
doctrine.system_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '@doctrine.system_cache_pool'
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
config/packages/doctrine.yaml
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
types:
json: Sonata\Doctrine\Types\JsonType
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
Article.php
...
/**
* @ORM\ManyToOne(targetEntity="App\Application\Sonata\MediaBundle\Entity\Gallery");
*/
private $gallery;
...
As i wrote in development mode everything is working fine.
The problem persists even though I did (many times):
- APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear
- php bin/console cache:clear
- remove var/cache and var/log directories, and create them again
- php bin/console doctrine:cache:clear-metadata
- restart apache
- change permissions (777) to uploads folder
- configure apcu -How to configure apcu for doctrine in Symfony5
- use Symfony cache pool - https://github.com/symfony/symfony/issues/24545#issuecomment-336419270
- try this - Doctrine 2.5: Unrecognized field (but only in Symfony's prod mode)
Any ideas what else can I do? I think there is a problem with cache ... somewhere.
prod
schema up to date? – msg