mysql - Doctrine/Symfony 更改单个列的字符集

标签 mysql symfony doctrine-orm doctrine

在 mysql 中我可以做:

ALTER TABLE T MODIFY column_name VARCHAR(32) CHARACTER SET ASCII;

有没有办法在 Doctrine/Symfony 中做到这一点?我试过(除了谷歌搜索):

/**
 * @ORM\Column(type="string", unique=true, length=32, nullable=false, options={"charset"="ASCII"} )
 */

不起作用,尽管 doctrine:schema:update 生成一个 ALTER TABLE 语句,但该语句不包含字符集定义。

为什么我需要这个:我有一个 string(32) 列,我希望它有索引并且是唯一的。 ASCII col 的 Mysql 索引长度为 32 字节,而 utf8 col 的索引长度为 32*3=96 字节。有点浪费:)

最佳答案

在 doctrine irc channel 上讨论后:

https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2549

public function getColumnCharsetDeclarationSQL($charset)
{
    return '';
}

所以这个功能似乎是在 Doctrine 中计划的,但从未实现。

有一个悬而未决的问题: https://github.com/doctrine/dbal/issues/2326

至于我的用例,我决定为我的索引使用 binary 列类型而不是 ascii,Doctrine 似乎很好地理解了这一点。

关于mysql - Doctrine/Symfony 更改单个列的字符集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35528179/

相关文章:

php - 检查mysql中是否存在一行

mysql - 访问 twig 中数组的单个元素

jquery - 使用ajax提交symfony2表单

mysql - Doctrine 从第二个表中选择与第一个表匹配的最后一条记录

php - 使用 Doctrine 和 ZF2 进行分页

php - Doctrine 2 : What does getResult return when there are no rows? 无效?

mysql - 如何从Mysql中读取单独的日期、单独的月份和单独的年份,其格式为10/12/2004

php - 在php中连接mysql数据库

MySQL 5.5 innodb_large_prefix 配置设置未生效

php - 无法使用 RabbitMQ 和 Symfony2 发送 Swift_Message