I have following entity:
class Employee {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $employeeId;
/**
* @ORM\Column(type="string", length=45, unique=true)
*/
protected $username;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
protected $email;
and I'm running following code:
$employee = new Employee();
$employee->setUsername('test');
$em = $this->getDoctrine()->getManager();
$em->persist($employee);
$em->flush();
As you can see I didn't set value for email column.
But on persists I get:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'email' cannot be null
because Doctrine adds all entity columns to the INSERT query and set null value for email column.
Is there a way to skip not set columns on insert? Or to make Doctrine insert '' (empty string) as default value for non null, string columns?