【问题标题】:Specify the table type/storage engine in Doctrine 2在 Doctrine 2 中指定表类型/存储引擎
【发布时间】:2011-11-23 07:17:16
【问题描述】:

那么如何在 Doctrine 2 中指定用于给定实体的存储引擎呢?

我正在创建一个需要全文索引的表,并且只有 MyISAM 存储引擎支持 MySQL 中的全文索引。

另一方面:看起来 Doctrine 2 不支持开箱即用的全文索引?也不是全文搜索?对吗?

【问题讨论】:

标签: php mysql full-text-search doctrine-orm myisam


【解决方案1】:

更新:

查看关于添加 "@Table(name="table_name",options={"engine"="MyISAM"})" 的评论,这是更好的答案。

======= 以下原文===========

这是未经测试的代码,旨在帮助您找到答案,但您需要阅读大量 Doctrine2 代码才能弄清楚您想要什么。我花了大约 30 分钟阅读代码,但找不到将 $options 数组通过 ORM 层推送到此 DBAL 层函数的方法。

查看 Doctrine/DBAL/Platforms/MySQLPlatform.php

427         // get the type of the table
428         if (isset($options['engine'])) {
429             $optionStrings[] = 'ENGINE = ' . $options['engine'];
430         } else {
431             // default to innodb
432             $optionStrings[] = 'ENGINE = InnoDB';
433         }

尝试硬编码what engine 想要在那里。它几乎肯定会破坏一些东西(例如,外键dont work in MyISAM

【讨论】:

  • 您可以使用@Table(name="table_name",options={"engine"="MyISAM"})为表格设置此项
  • @PaulJacobse 您应该将此作为答案发布
【解决方案2】:

如果您使用的是教义2 迁移..

$table = $schema->createTable('user');
$table->addColumn('id', 'integer');
$table->addOption('engine' , 'MyISAM');
$table->setPrimaryKey(array('id'));

【讨论】:

    【解决方案3】:

    我晚了两年,但知道这一点很重要,因为由于某种原因没有记录在案, 我们一直在努力实现这一目标,但这就是解决方案

    /**
     * ReportData
     *
     * @ORM\Table(name="reports_report_data",options={"engine":"MyISAM"})
     * @ORM\Entity(repositoryClass="Jac\ReportGeneratorBundle\Entity\ReportDataRepository")
     */
    class ReportData
    {
    

    【讨论】:

    • 请只注意 options={"engine":"MyISAM"}
    • 谢谢!不知道为什么没有将其标记为答案,奇怪。
    猜你喜欢
    • 1970-01-01
    • 2013-07-06
    • 2010-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-06
    • 2023-04-05
    相关资源
    最近更新 更多