Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Doctrine TEXT type?

I have this annotation:

/**
 * @ORM\Column(name="notes", type="string", length=65532, nullable=true)
 */
protected $notes;

According to this document - http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html#id102 because it's less than 65535 it should be TEXT?

But the column is created as MEDIUMTEXT.

How do I fix this?

like image 551
b85411 Avatar asked Jan 29 '15 05:01

b85411


People also ask

What is Doctrine in Symfony?

Symfony provides all the tools you need to use databases in your applications thanks to Doctrine, the best set of PHP libraries to work with databases. These tools support relational databases like MySQL and PostgreSQL and also NoSQL databases like MongoDB.

What is entity Symfony?

Well, entity is a type of object that is used to hold data. Each instance of entity holds exactly one row of targeted database table. As for the directories, Symfony2 has some expectations where to find classes - that goes for entities as well.

What is Symfony repository?

A repository is a way to retrieve entities, so put on repositories any method you need to get them, such as getUserByEmail or whatever.


2 Answers

You need to set the length:

To TINYTEXT => length = 255
To TEXT => length = 65535
To MEDIUMTEXT = 16777215
Default: LONGTEXT

Then, for example if you need an type text, it's necessary:

/**
* @ORM\Column(name="description", type="text", length=65535)
*/
like image 33
Cleuber Avatar answered Oct 10 '22 21:10

Cleuber


You are referencing not correct type in the documentation. In your code you have type="string" but your reference to documentation is related to type="object".

If you read the part of table above in the referenced docs you will see that string is casted to VARCHAR in MySQL if length does not exceed the maximum length for MySQL and is casted to MEDIUMTEXT if length exceeds.

But If you want to get explicitly TEXT field you will need to define your column with type="text".

like image 66
Michael Sivolobov Avatar answered Oct 10 '22 20:10

Michael Sivolobov