加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

symfony – Doctrine2忽略数据库表

发布时间:2020-12-12 16:56:15 所属栏目:MsSql教程 来源:网络整理
导读:我使用的是Doctrine 2,我想生成一个我的数据库的ORM,但是我不想选择db的所有表. 例如,在这个db: 表1没有主键 表2正常 我想用这个命令选择只有表2: doctrine:mapping:convert --from-database yml ./src/Application/TestBundle/Resources/config/doctrine/m
我使用的是Doctrine 2,我想生成一个我的数据库的ORM,但是我不想选择db的所有表.

例如,在这个db:

>表1没有主键
>表2正常

我想用这个命令选择只有表2:

doctrine:mapping:convert --from-database yml ./src/Application/TestBundle/Resources/config/doctrine/metadata/orm --filter="Table2"

我有一个错误:

Table Table_1 has no primary key. Doctrine does not support reverse engineering from tables that don’t have a primary key.

好的,我知道,但我不希望我的表1在我的ORM.

当我的表1有主键我可以过滤表…

如何解决这个问题?

我看到这个:
Generating a single Entity from existing database using symfony2 and doctrine

但它不行.

我回答我的问题

在你的配置中:config.yml,添加schema_filter,在我的情况下:

schema_filter: ~^(?!Table1)~

解决方法

如果您使用Doctrine2没有Symfony,那么您应该将此行添加到您的引导:
// With this expression all tables prefixed with Table1 will ignored by the schema tool.
$entityManager->getConnection()->getConfiguration()->setFilterSchemaAssetsExpression("~^(?!Table1)~");

整个bootstrap看起来像

<?php
// bootstrap.php

use DoctrineORMToolsSetup;
use DoctrineORMEntityManager;


// Include Composer Autoload (relative to project root).
require_once "vendor/autoload.php";

// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$paths = array(__DIR__."/doctrine/entities");

$config = Setup::createAnnotationMetadataConfiguration($paths,$isDevMode);
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/doctrine/yaml"),$isDevMode);

// the connection configuration
$dbParams = array(
  'driver'   => 'pdo_mysql','user'     => 'username','password' => 'password','dbname'   => 'database',);

/** @var $entityManager DoctrineORMEntityManager */
$entityManager = EntityManager::create($dbParams,$config);


// Set the other connections parameters
$conn = $entityManager->getConnection();


$platform = $conn->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum','string');


// With this expression all tables prefixed with t_ will ignored by the schema tool.
$conn->getConfiguration()->setFilterSchemaAssetsExpression("~^(?!t__)~");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读