Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update schema for create longtext field on MySQL data base on symfony

I want to update MySQL field from text to longtext using Doctrine schema.

Now my code is like this:

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

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

/**
 *@var string
 *@ORM\Column(name="body_fa", type="text", length=1000, nullable=true)
 */
private $body_fa;

/**
 *@var string
 *@ORM\Column(name="body_en", type="text", length=1000, nullable=true)
 */
private $body_en;

and the problem is when i change this field to this code

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

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

/**
 *@var string
 *@ORM\Column(name="body_fa", type="text", nullable=true)
 */
private $body_fa;

/**
 *@var string
 *@ORM\Column(name="body_en", type="text", nullable=true)
 */
private $body_en;

and run "php app/console doctrine:schema:update --force" command on console it said that "Nothing to update - your database is already in sync with the current entity metadata." How to change this field to longtext on mysql database.

I do the same on different part of the project. this is the code

/**
 * @ORM\Column(name="body", type="text", nullable=true)
 */
protected $body;

and after executing the "php app/console doctrine:schema:update --force" command on terminal this field is changed to longtext on MySQL database.

like image 592
Ehsan Avatar asked Apr 08 '14 12:04

Ehsan


1 Answers

I ran into this same issue. I found a solution after referencing this page: http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html

Specifying the length of the text field will have the correct type created in MySQL. For example: length=65535

See here: http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html#id100

A length between 256 and 65535 to use a "text" field in the database.

like image 193
nux Avatar answered Nov 15 '22 16:11

nux