我得到了一个带有这样字段的实体:
/**
* @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/