【问题标题】:Symfony 3.3 Doctrine Fixtures Load skipping SQL viewsSymfony 3.3 Doctrine Fixtures 加载跳过 SQL 视图
【发布时间】:2018-01-31 05:42:39
【问题描述】:

我正在尝试将 SQL 视图与 Doctrine 一起使用。

到目前为止一切正常,但是在运行基本的固定装置加载时我遇到了问题(没有选项)。我收到以下错误消息。

[Doctrine\DBAL\DBALException]
An exception occurred while executing 'DELETE FROM gp_items':

SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]View or function 'gp_items' is not updatable
because the modification affects multiple base tables.


[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]View or function 'gp_items' is not updatable
because the modification affects multiple base tables.


[PDOException]
SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]View or function 'gp_items' is not updatable
because the modification affects multiple base tables.

我查看了从捆绑包中加载固定装置的代码(“doctrine/doctrine-fixtures-bundle”:“^2.3”),我认为我必须对 ORMPurger 进行一些更改(Doctrine\Common\DataFixtures\Purger ) 但我不知道该怎么做。

所以我想知道如何覆盖特定类中的函数。

干杯!

【问题讨论】:

    标签: sql-server symfony doctrine-orm views


    【解决方案1】:

    好的,

    所以我决定分叉 DoctrineFixturesBundle 并在我的项目中使用我自己的版本。

    https://github.com/jbonnier/DoctrineFixturesBundle

    为了让 composer 使用它,我修改了我的 composer.json 文件,在最后一个右括号之前添加了以下代码。

    ,
        "repositories": [
            {
                "type": "vcs",
                "url": "https://github.com/jbonnier/DoctrineFixturesBundle"
            }
        ] 
    

    我还更改了我的 require-dev 语句以使用我的个人分支。

     "require-dev": {
        "doctrine/doctrine-fixtures-bundle": "dev-jbonnier",
       ...
    }
    

    编辑:

    补充说明。

    我目前正在使用捆绑包的 v2.4.1 版本。

    这是我对其所做的更改。

    文件:Command/LoadDataFixturesDoctrineCommand.php

    更改了第 113 行

    来自

    $purger = new ORMPurger($em);
    

    到

    $purger = new ORMPurger($em, $this->listViews($input->getOption('em')));
    

    在第 136 行之后向类添加函数

    /**
     * Return an array with all views names in the database. 
     *
     * @return array
     */
    protected function listViews($entityManager)
    {
        $em = $this->getContainer()->get('doctrine')->getManager($entityManager);
        $conn = $em->getConnection();
        $sm = $conn->getSchemaManager();
    
        $views = $sm->listViews();
        $rst = array();
    
        foreach ($views as $view)
        {
            array_push($rst, $view->getName());
        }
    
        return $rst;
    }
    

    【讨论】:

      【解决方案2】:

      我遇到了类似的问题。我很懒,所以我做了解决方法来以这种方式加载我们的固定装置。
      我找到了我感兴趣的干净解决方案

      bin/console -e=test doctrine:database:drop --if-exists --force
      bin/console -e=test doctrine:database:create --if-not-exists --no-interaction
      bin/console -e=test doctrine:migrations:migrate --no-interaction
      bin/console -e=test doctrine:fixtures:load --append --no-interaction
      

      【讨论】:

        猜你喜欢
        • 2018-11-20
        • 1970-01-01
        • 1970-01-01
        • 2011-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-08
        • 2018-04-18
        相关资源
        最近更新 更多