【问题标题】:Application works in app_dev.php, but not visible using app.php应用程序在 app_dev.php 中工作,但在 app.php 中不可见
【发布时间】:2017-11-27 08:09:21
【问题描述】:

我真的很困惑。我使用 Symfony 2.7 和学说作为其原生 ORM。 因此,当我使用 app_dev.php 启动它时,一切正常,但是当我使用 app.php 启动它时。

它只是不起作用。 在日志中它说

[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)"} [] 

这真的是可以自我解释的,所以它找不到 t0 因为它不存在。 我已经尝试清除缓存的学说并清除应用程序的一般缓存,但没有任何效果。 我用过这个命令 -

  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

有没有人知道这里发生了什么?

编辑:

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

}

这是我的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

【问题讨论】:

    标签: php symfony doctrine-orm doctrine symfony-2.7


    【解决方案1】:

    强制清除缓存:

    rm -rf var/cache/*
    

    确保该列存在,并且您的映射有效:

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

    这里没有魔法。

    【讨论】:

    • 嗨,迈克,感谢您的回复。我已经删除了缓存。 [映射] OK - 映射文件正确。 [数据库] OK - 数据库架构与映射文件同步。
    • 我已经检查了数据库本身是否一切正常,一切都很好。我不明白为什么当我使用 app_dev.php 时它会起作用?为什么在日志本身中它说它尝试使用不同的别名执行 select 语句?
    • 嗯,这不也是我的问题的解决方案吗? stackoverflow.com/questions/21536634/… 但是我不明白为什么当我使用 app_dev.php 时它会起作用?
    • 您是否正在以某种方式扩展您的实体?
    • 是的.. 我正在扩展它们。使用扩展名编辑了问题。
    【解决方案2】:

    所以这个问题的答案在于 config_prod.yml,它与 config_dev.yml 略有不同。

    而且缓存机制不同。我的 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
    

    我的 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
    

    我刚刚从 config_prod.yml 中注释掉了学说,突然间一切都正常了 :-) 或者您也可以在您的作品中启用 APC,然后它也可以正常工作。

    【讨论】:

      猜你喜欢
      • 2015-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多