I have a Symfony2 form with a variety of fields, including one optional text field called recap.
This recap field saves perfectly when there’s some text in it, but when the field is left blank, I get this error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'recap' cannot be null
That’s right – the column recap can’t be null. I set it that way on purpose. Null means unknown. When the user leaves recap blank, the value of recap is not unknown; it’s blank.
My question is how to get Symfony to save recap as '' when it’s blank, not null.
Go to your Entity and go to the declaration of the variables.
you can assign a default value for $recap.
Or otherway when you have the function setRecap you can check if empty or not set and set the value you expect.
Or you set the default Value in your form Type to ” but i think then its not what you expect.