Reputation: 587
I have a strange error, on my Symfony4 project. One of my relation is a ManyToOne with nullable true, like this:
class UserComic
{
...
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Series")
* @ORM\JoinColumn(name="id_series", referencedColumnName="id", nullable=true)
*/
private $series;
...
}
then I try to create a new UserComic with the $series attribute set to NULL, but i receive this error:
"Entity of type App\Entity\UserComic is missing an assigned ID for field 'series'. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly."
As the field is not setted to nullable. Any advice?
Upvotes: 0
Views: 765
Reputation: 1072
ID means UNIQ and NOT NULLABLE.
You are on a ManyToOne relatsionship (on the many side) that break the UNIQ property of ID
You set the joinColumn as nullable, that breaks the NOT NULLABLE PROPERTY
Upvotes: 0