Symfony5.4: Assert not null for property of entity not working

Viewed 20

I have a project where in the entity classes with

  • @Assert\NotNull(
    • payload={"severity"="error"},
    • message="field not be empty"
    • )

the validation of mandatory field takes place.

However, the above validation only works if the affected field is set to nullable=true. Which makes the field in the DB table as null=true.

If I set null=false for the field with Doctrine, the @Assert\NotNull() function will not works.

Is that correct that null=true has to be setted in order for the validation to work.

BTW I don't find this approach coherent

0 Answers
Related