symfony – Doctrine2忽略数据库表

前端之家收集整理的这篇文章主要介绍了symfony – Doctrine2忽略数据库表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用的是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 Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;


// 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 \Doctrine\ORM\EntityManager */
$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__)~");
原文链接:https://www.f2er.com/mssql/81203.html

猜你在找的MsSQL相关文章