Application works in app_dev.php, but not visible

2019-08-02 09:22发布

问题:

I am really confused. I am using Symfony 2.7 and doctrine as its native ORM. So everything works as it is supposed to work when I start it using app_dev.php, but when I start it using app.php.

It just doesn't work. In logs it says

[2017-11-27 09:02:51] request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\DBALException: "An exception occurred while executing 'SELECT t1.id AS id2, t1.code AS code3, t1.created AS created4, t1.updated AS updated5, t1.template_code AS template_code6, t1.label_attribute_id AS label_attribute_id7 FROM pim_catalog_family t1 WHERE t0.code = ? LIMIT 1' with params ["city_actions"]:  SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.code' in 'where clause'" at /var/www/html/pim-community-standard/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php line 91 {"exception":"[object] (Doctrine\\DBAL\\DBALException(code: 0): An exception occurred while executing 'SELECT t1.id AS id2, t1.code AS code3, t1.created AS created4, t1.updated AS updated5, t1.template_code AS template_code6, t1.label_attribute_id AS label_attribute_id7 FROM pim_catalog_family t1 WHERE t0.code = ? LIMIT 1' with params [\"city_actions\"]:\n\nSQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.code' in 'where clause' at /var/www/html/pim-community-standard/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:91, PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.code' in 'where clause' at /var/www/html/pim-community-standard/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:694)"} [] 

This is really self explainable, so it can't find t0 because it doesn't exists. I have tried already to clear the cache for doctrine and to clear general cache of the application, but nothing works. I have used this commands -

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

php app/console cache:clear --env=prod

Does anyone have any clue what is happening in here ?

Edit:

    <?php
/**
 * Created by PhpStorm.
 * User: nebo
 * Date: 2.11.17.
 * Time: 10.50
 */

namespace Iclei\Bundle\BackendBundle\Entity;

use Pim\Bundle\CatalogBundle\Entity\Family as BaseFamily;

class Family extends BaseFamily
{
    protected $template_code;

    /**
     * @return mixed
     */
    public function getTemplateCode()
    {
        return $this->template_code;
    }

    /**
     * @param mixed $template_code
     */
    public function setTemplateCode($template_code)
    {
        $this->template_code = $template_code;
    }

}

And this is my family.orm.yml

Bundle\BackendBundle\Entity\Family:
    type: entity
    table: pim_catalog_family
    changeTrackingPolicy: DEFERRED_EXPLICIT
    repositoryClass: Pim\Bundle\CatalogBundle\Doctrine\ORM\Repository\FamilyRepository
    uniqueConstraints:
        pim_category_code_uc:
            columns:
                - code
    fields:
        template_code:
            type: text
            nullable: true

回答1:

Force clear the cache:

rm -rf var/cache/*

Make sure the column exists, also that your mapping is valid:

bin/console -e=prod doctrine:schema:validate

There's no magic here.



回答2:

So this answer to this problem lies in config_prod.yml which is slighly different from the config_dev.yml.

And it is different in caching mechanism. Looks of my config_prod.yml

        imports:
        - { resource: config.yml }

    doctrine:
        orm:
            entity_managers:
                default:
                    metadata_cache_driver: apc
                    result_cache_driver:   apc
                    query_cache_driver:    apc

    monolog:
        handlers:
            main:
                type:         fingers_crossed
                action_level: warning
                handler:      nested
            nested:
                type: stream
                path: %kernel.logs_dir%/%kernel.environment%.log
                level: info
            console:
                type:  console

    oro_assetic:
        css_debug:      ~
        css_debug_all:  false

Looks of my config_dev.yml

    imports:
    - { resource: config.yml }

framework:
    router:   { resource: "%kernel.root_dir%/config/routing_dev.yml" }
    profiler: { only_exceptions: false }

web_profiler:
    toolbar: true
    intercept_redirects: false

monolog:
    handlers:
        main:
            type:  stream
            path:  "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
        firephp:
            type:  firephp
            level: info

oro_assetic:
    css_debug:      ~
    css_debug_all:  false

swiftmailer:
    disable_delivery: true

parameters:
    apy_js_form_validation.yui_js: false

I have just commented out doctrine from config_prod.yml and all of the sudden everything is working :-) Or you could enable APC on your production as well and then it is going to work as well.