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

25,349

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.

Share:
25,349
Ehsan
Author by

Ehsan

I am web developer at Darkoob web agency. I had experience with Symfony 1 & 2 and Laravel 5 frameworks and WordPress CMS. I am somehow full-stack PHP developer with strong knowledge of front-end.

Updated on July 09, 2022

Comments

  • Ehsan
    Ehsan almost 2 years

    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.

  • Rob K
    Rob K about 5 years
    References missing. In the repo you can reference the text type here: github.com/doctrine/dbal/blob/… So the column definition becomes: @ORM\Column(name="<name>", type="text", nullable=true) without the length at all (because LONGTEXT is the default for column types of 'text')
  • Guillaume Harari
    Guillaume Harari about 5 years