php - Doctrine ORM 唯一字符串不区分大小写

标签 php symfony doctrine-orm

我得到了一个带有这样字段的实体:

/**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255, unique=true)
     */
    private $name;

但是,如果我尝试将名称中的拼写错误从“test”改成“Test”,我会收到一个错误消息,提示该名称已被占用!知道为什么会这样吗?唯一索引不区分大小写吗?

最佳答案

你的问题是因为你有 utf8_general_ci 整理注意 _ci 这意味着 不区分大小写,反过来这意味着数据库对待“测试”,“测试”,“TEst”等。

您必须手动将数据库中的列排序规则更改为 utf8_bin,或者更改为 utf8_xxx_cs(其中 xxx 是语言名称),如果您恰好有所需的语言。

来自 Doctrine ORM FAQ:

4.1.1. How do I set the charset and collation for MySQL tables?

You can’t set these values inside the annotations, yml or xml mapping files. To make a database work with the default charset and collation you should configure MySQL to use it as default charset, or create the database with charset and collation details. This way they get inherited to all newly created database tables and columns.

关于php - Doctrine ORM 唯一字符串不区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20311269/

相关文章:

php - jQuery数据表在PHP中不起作用

symfony - 无法将 symfony 应用程序部署到 Heroku

mysql - 我如何调用存储过程(使用 zf2,学说 2)?

php - 设置相等运算符的 Doctrine 更新查询

php - 使用 PHP 解析推送通知

php - 如何使 html 选择框默认为最新的数据库条目

PHP 标签关闭——什么时候需要?

php - 如何在没有 SSH 和 CLI 访问生产的情况下部署 symfony 项目

symfony - 如何覆盖每个环境的 Symfony2 语义配置?

doctrine-orm - Symfony 3、Doctrine 2、自定义 fixture 加载器