DDC-3953: Text field is returned null from MySQL even if field has text #4833

Open
opened 2026-01-22 14:50:13 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 14, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user gabiudrescu:

I have an entity where I was trying to add a new text field (description). The YML is listed below:

description:
            type: text
            nullable: true

I have run the required commands:

  • php app/console doctrine:generate:entities Namespace
  • php app/console doctrine:schema:update

The following SQL command ran:

ALTER TABLE image ADD description LONGTEXT DEFAULT NULL;

I have persisted a few entities where the description contains a hash sign (#) and after trying to retrieve that description in an HTML page, I noticed the field was empty (null).

So, in order to remove all doubts about doing something wrong, I did the following experiment:

        $image = new Image();
        $image->setDescription('test');
        $this->getDoctrine()->getManager()->persist($image);
        $this->getDoctrine()->getManager()->flush();

        var_dump($image);

This code rendered:

object(GabiU\Bundle\Entity\Image)[394]
 private 'description' => string 'test' (length=4)

But if I retrieve the same entity by ID from my database, the description field is null:

$image = $this->getDoctrine()->getRepository('Bundle:Image')->find(141);
        var_dump($image);
        die();
object(GabiU\RomaniaMagicaBundle\Entity\Image)[406]
  private 'description' => null

Also, other entities, if returned from MySQL they have the description field null - although PHPMyAdmin shows the field with text.

I have tried this solution http://stackoverflow.com/questions/22282490/doctrine-2-entity-field-is-null-when-database-field-contains-certain-special-cha or http://stackoverflow.com/questions/16079081/doctrine-2-3-text-field-is-not-saved-because-of-special-characters but with no luck :(

Any ideas why this arbitrary field stopped working as supposed?

Originally created by @doctrinebot on GitHub (Oct 14, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user gabiudrescu: I have an entity where I was trying to add a new text field (description). The YML is listed below: ``` description: type: text nullable: true ``` I have run the required commands: - php app/console doctrine:generate:entities Namespace - php app/console doctrine:schema:update The following SQL command ran: ``` sql ALTER TABLE image ADD description LONGTEXT DEFAULT NULL; ``` I have persisted a few entities where the description contains a hash sign (#) and after trying to retrieve that description in an HTML page, I noticed the field was empty (null). So, in order to remove all doubts about doing something wrong, I did the following experiment: ``` $image = new Image(); $image->setDescription('test'); $this->getDoctrine()->getManager()->persist($image); $this->getDoctrine()->getManager()->flush(); var_dump($image); ``` This code rendered: ``` object(GabiU\Bundle\Entity\Image)[394] private 'description' => string 'test' (length=4) ``` But if I retrieve the same entity by ID from my database, the description field is null: ``` $image = $this->getDoctrine()->getRepository('Bundle:Image')->find(141); var_dump($image); die(); ``` ``` object(GabiU\RomaniaMagicaBundle\Entity\Image)[406] private 'description' => null ``` Also, other entities, if returned from MySQL they have the description field null - although PHPMyAdmin shows the field with text. I have tried this solution http://stackoverflow.com/questions/22282490/doctrine-2-entity-field-is-null-when-database-field-contains-certain-special-cha or http://stackoverflow.com/questions/16079081/doctrine-2-3-text-field-is-not-saved-because-of-special-characters but with no luck :( Any ideas why this arbitrary field stopped working as supposed?
admin added the Bug label 2026-01-22 14:50:13 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 14, 2015):

Comment created by gabiudrescu:

same issue with other already created entities. but with newly created entities it works. I suspect some mysql issue.

@doctrinebot commented on GitHub (Oct 14, 2015): Comment created by gabiudrescu: same issue with other already created entities. but with newly created entities it works. I suspect some mysql issue.
Author
Owner

@doctrinebot commented on GitHub (Oct 15, 2015):

Comment created by gabiudrescu:

fresh new ideas in the morning: dropping the database, creating it again. now it works - entity description is retrieved accordingly from database.

I have no idea why last night wasn't working. any feedback is much appreciated - i hate the feeling of having something working and don't know why.

@doctrinebot commented on GitHub (Oct 15, 2015): Comment created by gabiudrescu: fresh new ideas in the morning: dropping the database, creating it again. now it works - entity description is retrieved accordingly from database. I have no idea why last night wasn't working. any feedback is much appreciated - i hate the feeling of having something working and don't know why.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4833