我有这个注释:
/**
* @ORM\Column(name="notes", type="string", length=65532, nullable=true)
*/
protected $notes;
根据这份文件 - http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html#id102因为小于 65535 应该是 TEXT 吧?
但该列被创建为 MEDIUMTEXT。
我该如何解决这个问题?
最佳答案
您在文档中引用的类型不正确。在您的代码中,您有 type="string"
但您对文档的引用与 type="object"
有关。
如果您阅读了引用文档中的上表部分,您将看到 string
在 MySQL 中被强制转换为 VARCHAR
如果 length
确实如此不超过 MySQL 的最大长度,如果 length
超过,则转换为 MEDIUMTEXT
。
但是,如果您想明确获得 TEXT
字段,则需要使用 type="text"
和 length
定义列。取决于定义的 length
Doctrine according to documentation将生成以下类型之一:
+----------------------------------+-------------+
| `length` is less or equal to | casted type |
+----------------------------------+-------------+
| 2 ^ 8 - 1 = 255 | TINYTEXT |
| 2 ^ 16 - 1 = 65535 | TEXT |
| 2 ^ 24 - 1 = 16777215 | MEDIUMTEXT |
| 2 ^ 32 - 1 = 4294967295 or empty | LONGTEXT |
+----------------------------------+-------------+
所以要在 MySQL 上显式设置 TEXT
类型,你需要下一个注解:
/**
* @ORM\Column(name="notes", type="text", length=65535)
*/
protected $notes;
关于mysql - 如何获得 Doctrine TEXT 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28207647/