ExistingArticle
,Category
Two entities, the relationship is onetomany;
Article does not have to correspond to category. If article does not have a corresponding category, then category_id =0;
Then the question comes
$article = new Article();
$article->setTitle('This is a test article');
//...
$em->persist($article);
$em->flush();
The error is reported as follows, category_id cannot be empty
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'category_id' cannot be null
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'category_id' cannot be null
How to set up this unnecessary Association
Set the nullable attribute of Article::$category to true
``
class Article
{
}
``