mysql - 在 Doctrine 中配置索引文本长度 MySQL

标签 mysql symfony doctrine-orm

我的数据库中有一个文本字段和前 10 个字符的索引。我如何在我的 Doctrine 实体中指定它?

我在任何地方都找不到关于索引的数据库特定选项的任何信息:/

这是我的“部分”MySQL 创建语句:

 KEY `sourceaddr_index` (`sourceaddr`(10)),

这是我的@Index 教义:

 @ORM\Index(name="sourceaddr_index", columns={"sourceaddr"}, options={}), 

这不会影响正常使用,但我在将开发部署到新笔记本电脑并根据我的实体创建数据库时注意到了这个问题......

任何帮助将不胜感激:)

最佳答案

从 Doctrine 2.9 开始可能,请参阅:https://github.com/doctrine/dbal/pull/2412

@Index(name="slug", columns={"slug"}, options={"lengths": {191}})

不幸的是,Doctrine 似乎对空白位置非常挑剔,所以例如update --dump-sql 产生:

 DROP INDEX slug ON wp_terms;
 CREATE INDEX slug ON wp_terms (slug(191));

即使您执行了这些,它们的消息也会保留在那里(使用 MariaDB 10.3.14 测试)。

关于mysql - 在 Doctrine 中配置索引文本长度 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32539973/

相关文章:

php - Symfony2/Doctrine2 : Issues managing multiple entity manager inside a listener

php - 学说顺序按注释。基于关联实体对实体关联进行排序。

MySQL 和 PDO : two languages in one table using UTF-8 collation

mysql - 无法将 bigdecimal 分配给模型中的字段

php - ApiPlatform - 规范化后将 DTO 的字段传递给不同的服务

design-patterns - symfony2中使用的设计模式

symfony - Sensiolabs 洞察力 : Twig templates should not contain business logic

symfony - Doctrine2 查询生成器在连接后仅返回相关实体

MySQL(和 WordPress): select rows containing the highest value in one column and order by another

mysql - MySQL如何约束列?