【问题标题】:"NotNullConstraintViolationException" Exception although the value shoud not be NULL“NotNullConstraintViolationException”异常,尽管值不应为 NULL
【发布时间】:2017-11-06 13:02:06
【问题描述】:

我使用以下函数来保护数据库中持久化的数据。

public function storeAppendDataDFu1($entity, $pKpPatientid)
{
    $em = $this->getDoctrine()->getManager();
    $session = $this->getRequest()->getSession();

    $entity1 = $this->getDoctrine()
        ->getRepository('DataLiveBundle:DataAPatient')
        ->find($pKpPatientid);

    if (!$entity) {
        throw $this->createNotFoundException('Unable to find DataDFu1 entity.');
    }
    $entity->setFu1AgeRef("5");
    //$pSnnid = $entity->getPSnnid();
    $entity->setFu1KfPatientid($entity1);
    echo $entity->getFu1AgeRef(); 
    $em->persist($entity);
    $em->flush();
    $session->getFlashBag()->add(
            'notice',
            'Your changes to the DataDFu1 of ID: "'."xyz". '" was saved!'
    );
   // return $entity->getPKpPatientid();
}

每当我想要安全的东西时,我都会收到此错误:NotNullConstraintViolationException

我知道,FU1_Age_Ref 不应该有 null 值,这就是我用这行代码扩展我的函数的原因:

        $entity->setFu1AgeRef("5");

但是实体没有得到这个值(我无法理解)并且异常仍然存在。所以我不知道如何解决这个问题。

实体定义:

  fu1AgeCalc:
        type: decimal
        nullable: true
        precision: 18
        scale: 4
        column: FU1_Age_calc
    fu1AgeRef:
        type: integer
        nullable: true
        column: FU1_Age_ref
    fu1DevTest:
        type: decimal
        nullable: true
        precision: 18
        scale: 4
        column: FU1_Dev_test

感谢您的反馈。

【问题讨论】:

  • 请显示您的实体定义
  • 哇,那个插入是疯狂!你必须确保你有相同数量的项目,?和价值观。然后确保订单是好的。您可能会尝试在不应该插入 null 的位置,只是因为顺序错误。
  • @Nic3500 虽然插入可能确实很疯狂,但它实际上是由教义生成的,所以没有真正需要尝试匹配的东西。这更像是某人制作了一个疯狂的实体,然后在不了解如何调试的情况下尝试将其持久化。
  • firstone 我无法选择我的数据模型..所以我继承了它。我认为出现异常是因为在 entity->setFu1AgeRef() 函数之后不会更改变量 Fu1AgeRef 中的值。因此,该字段中值为 NULL 的实体将受到保护。但是为什么 vlaue 不会改变.. 是我想要安全的实体和我调用函数 setFu1AgeRef() 的实体不一样..mhm.. 对不起,但我真的没有看到错误

标签: php sql symfony doctrine


【解决方案1】:

我找到了解决方案,最后是数据库中的错误配置。 FU1_poorComp 不允许为空。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-29
    • 2014-09-26
    • 2022-07-22
    • 2014-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多