I'm new to Symfony and doctrine as well but I'm doing things based on the Documentation.
The error I get is: Error: Call to a member function format() on string
and the code it gives for is in
vendor\doctrine\dbal\lib\Doctrine\DBAL\Types\DateType.php at line 53 -
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return ($value !== null)
? $value->format($platform->getDateFormatString()) : null;
}
/**
The problem is that it tries to format the value of the Date type field. Here's my entity code generated with doctrine:
/**
* @var \DateTime
*/
private $availableDate = '0000-00-00';
If I remove the default value of the Date field then it does not throw me this exception, but the problem is that this field can not contain null value in the database (MySQL), so if remove the default value and leave it blank it's going to try to insert null into it and I get error from MySQL.
I don't have a constructor, I use doctrine to insert new like thisL
$product = new PsProduct2();
$em = $this->getDoctrine()->getManager();
$em->persist($product);
$em->flush();
How can this be fixed?