How to fix 'Missing value for primary key' #6255

Closed
opened 2026-01-22 15:29:38 +01:00 by admin · 8 comments
Owner

Originally created by @denis75chine on GitHub (Jun 21, 2019).

Originally assigned to: @denis75chine on GitHub.

The problem comes back but this time I do not understand what happens:

I am in symfony 3.4

THE entities ARE WELL IN Autoincrement at the level of the primary key

I have the following error:

Uncaught PHP Exception Doctrine \ Common \ Proxy \ Exception \ OutOfBoundsException: "Missing value for primary key contactId on Lea \ PrestaBundle \ Entity \ EgwAddressbook"

My entity :
`<?php

namespace Lea\PrestaBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;

use Doctrine\ORM\Mapping as ORM;

/**

  • Lea\PrestaBundle\Entity\EgwAddressbook

  • @ORM\Table(name="egw_addressbook")

  • @ORM\Entity(repositoryClass="Lea\PrestaBundle\Entity\EgwAddressbookRepository")
    /
    class EgwAddressbook
    {
    /
    *

    • @var integer $contactId
    • @ORM\Column(name="contact_id", type="integer", nullable=false)
    • @ORM\Id
    • @ORM\GeneratedValue(strategy="IDENTITY")
      */
      private $contactId;

    /**

    • @var string $contactTid
    • @ORM\Column(name="contact_tid", type="string", length=1, nullable=true)
      */
      private $contactTid;

    /**

    • @var integer $contactOwner
    • @ORM\Column(name="contact_owner", type="bigint", nullable=false)
      */
      private $contactOwner;

    /**

ETC ETC ...
...`

This entity EgwAdressBook is linked with the entity EgwPrestation :

`/**

  • @ORM\ManyToOne(targetEntity="EgwAddressbook", inversedBy="prestationsP")
  • @ORM\JoinColumn(name="id_contact_prescripteur", referencedColumnName="contact_id")
    */
    private $contactPr;
    id_contact_prescripteur and contact_id are of the same type (integer) (question already asked)`

When running the EgwPrestation repository (hereinafter), I get the error message:

"Missing value for primary key contactId on Lea \ PrestaBundle \ Entity \ EgwAddressbook"

`$dql=" SELECT p,pr,ac,t
FROM LeaPrestaBundle:EgwPrestation p
inner join p.prestataire pr
left join p.account ac
left join p.dispositif t
".$sqlPlus."
order by p.dateDebut desc";

Thanks for your help!

I keep searching...

Originally created by @denis75chine on GitHub (Jun 21, 2019). Originally assigned to: @denis75chine on GitHub. The problem comes back but this time I do not understand what happens: I am in symfony 3.4 THE entities ARE WELL IN Autoincrement at the level of the primary key I have the following error: Uncaught PHP Exception Doctrine \ Common \ Proxy \ Exception \ OutOfBoundsException: "Missing value for primary key contactId on Lea \ PrestaBundle \ Entity \ EgwAddressbook" My entity : `<?php namespace Lea\PrestaBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; /** * Lea\PrestaBundle\Entity\EgwAddressbook * * @ORM\Table(name="egw_addressbook") * @ORM\Entity(repositoryClass="Lea\PrestaBundle\Entity\EgwAddressbookRepository") */ class EgwAddressbook { /** * @var integer $contactId * * @ORM\Column(name="contact_id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $contactId; /** * @var string $contactTid * * @ORM\Column(name="contact_tid", type="string", length=1, nullable=true) */ private $contactTid; /** * @var integer $contactOwner * * @ORM\Column(name="contact_owner", type="bigint", nullable=false) */ private $contactOwner; /** ETC ETC ... ...` This entity EgwAdressBook is linked with the entity EgwPrestation : `/** * @ORM\ManyToOne(targetEntity="EgwAddressbook", inversedBy="prestationsP") * @ORM\JoinColumn(name="id_contact_prescripteur", referencedColumnName="contact_id") */ private $contactPr; id_contact_prescripteur and contact_id are of the same type (integer) (question already asked)` When running the EgwPrestation repository (hereinafter), I get the error message: > "Missing value for primary key contactId on Lea \ PrestaBundle \ Entity \ EgwAddressbook" `$dql=" SELECT p,pr,ac,t FROM LeaPrestaBundle:EgwPrestation p inner join p.prestataire pr left join p.account ac left join p.dispositif t ".$sqlPlus." order by p.dateDebut desc"; Thanks for your help! I keep searching...
admin added the IncompleteMissing Tests labels 2026-01-22 15:29:38 +01:00
admin closed this issue 2026-01-22 15:29:38 +01:00
Author
Owner

@Ocramius commented on GitHub (Jun 22, 2019):

Seems like one of the various tables involved has a null primary key here. That should be filtered out by the hydration process, so something else is happening.

Can you reduce this to a simpler integration test case, like the ones in the ORM test suite?

Can't really help without reproducing it.

@Ocramius commented on GitHub (Jun 22, 2019): Seems like one of the various tables involved has a `null` primary key here. That should be filtered out by the hydration process, so something else is happening. Can you reduce this to a simpler integration test case, like the ones in the ORM test suite? Can't really help without reproducing it.
Author
Owner

@denis75chine commented on GitHub (Jun 22, 2019):

Thanks Ocramius for your answer.

It's probably a problem between 2 entities 👍

The link between entities egw_accounts and egw_addressbook is : ACCOUNT_ID

In the database, about the field ACCOUNT_ID there are exactly the same values in entities egw_accounts and egw_addressbook 👍
egw_accounts->ACCOUNT_ID = egw_addressbook->ACCOUNT_ID

SO, perhaps it's in the definition of entities that there's a problem

Remember that, i didnt have the problem in SYMFONY 2 : but in SYMFONY 3.4, the problem appears

THANKS for your help!

ENTITY EGW_ACCOUNTS 👍

class EgwAccounts { /** * @var integer $accountId * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\OneToOne(targetEntity="EgwAddressbook", cascade={"persist", "merge", "remove"}) * @ORM\JoinColumn(name="account_id", referencedColumnName="account_id") */ private $accountId;

With the SETTER :

`
/**
* Set accountId
*
* @param Lea\PrestaBundle\Entity\EgwAddressbook $accountId
* @return EgwAccounts
*/
public function setAccountId(\Lea\PrestaBundle\Entity\EgwAddressbook $accountId)
{
$this->accountId = $accountId;

    return $this;
}`

THE ENTITY EGW_ADDRESSBOOK 👍

/** * @var integer $accountId * @ORM\Column(name="account_id", type="integer", nullable=true) */ private $accountId;

@denis75chine commented on GitHub (Jun 22, 2019): Thanks Ocramius for your answer. It's probably a problem between 2 entities 👍 The link between entities egw_accounts and egw_addressbook is : ACCOUNT_ID In the database, about the field ACCOUNT_ID there are exactly the same values in entities egw_accounts and egw_addressbook 👍 egw_accounts->ACCOUNT_ID = egw_addressbook->ACCOUNT_ID SO, perhaps it's in the definition of entities that there's a problem Remember that, i didnt have the problem in SYMFONY 2 : but in SYMFONY 3.4, the problem appears THANKS for your help! ENTITY EGW_ACCOUNTS 👍 `class EgwAccounts { /** * @var integer $accountId * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\OneToOne(targetEntity="EgwAddressbook", cascade={"persist", "merge", "remove"}) * @ORM\JoinColumn(name="account_id", referencedColumnName="account_id") */ private $accountId;` With the SETTER : ` /** * Set accountId * * @param Lea\PrestaBundle\Entity\EgwAddressbook $accountId * @return EgwAccounts */ public function setAccountId(\Lea\PrestaBundle\Entity\EgwAddressbook $accountId) { $this->accountId = $accountId; return $this; }` THE ENTITY EGW_ADDRESSBOOK 👍 ` /** * @var integer $accountId * @ORM\Column(name="account_id", type="integer", nullable=true) */ private $accountId;`
Author
Owner

@Ocramius commented on GitHub (Jun 22, 2019):

Is it intended to be a column or an association? You seem to set an association in a column property...

@Ocramius commented on GitHub (Jun 22, 2019): Is it intended to be a column or an association? You seem to set an association in a column property...
Author
Owner

@denis75chine commented on GitHub (Jun 22, 2019):

The column is account_id : it's a onetoone association.
The setter of account_id in EgwAcccounts :

` /**
* Set accountId
*
* @param Lea\PrestaBundle\Entity\EgwAddressbook $accountId
* @return EgwAccounts
*/
public function setAccountId(\Lea\PrestaBundle\Entity\EgwAddressbook $accountId)
{
$this->accountId = $accountId;

    return $this;
}`

This works in Symfony 2

I am desespared...

@denis75chine commented on GitHub (Jun 22, 2019): The column is account_id : it's a onetoone association. The setter of account_id in EgwAcccounts : ` /** * Set accountId * * @param Lea\PrestaBundle\Entity\EgwAddressbook $accountId * @return EgwAccounts */ public function setAccountId(\Lea\PrestaBundle\Entity\EgwAddressbook $accountId) { $this->accountId = $accountId; return $this; }` This works in Symfony 2 I am desespared...
Author
Owner

@Ocramius commented on GitHub (Jun 22, 2019):

Please read up on association mappings in the docs: associations are not set via @Column

@Ocramius commented on GitHub (Jun 22, 2019): Please read up on association mappings in the docs: associations are not set via `@Column`
Author
Owner

@denis75chine commented on GitHub (Jun 23, 2019):

Thank you for your answer

@denis75chine commented on GitHub (Jun 23, 2019): Thank you for your answer
Author
Owner

@denis75chine commented on GitHub (Jun 23, 2019):

I ve got exactly the same problem after changing code (see below)

"Missing value for primary key egwAddressbook on Lea\PrestaBundle\Entity\EgwAccounts"

Entity EgwAccounts :
`
/**
* @ORM\OneToOne(targetEntity="EgwAddressbook", inversedBy="EgwAccounts")
* @ORM\JoinColumn(name="account_id", referencedColumnName="account_id")
* @ORM\Id
*/
protected $egwAddressbook;

public function setEgwAddressbook(EgwAddressbook $egwAddressbook)
{
	$this->egwAddressbook = $egwAddressbook;

	return $this;
}`

entity EgwAddressbook :

`
/**
* @ORM\OneToOne(targetEntity="EgwAccounts", mappedBy="EgwAddressbook")
*/
protected $egwAccounts;

public function getEgwAccounts(EgwAccounts $egwAccounts)
{
	return $this->egwAccounts;
}`
@denis75chine commented on GitHub (Jun 23, 2019): I ve got exactly the same problem after changing code (see below) **"Missing value for primary key egwAddressbook on Lea\PrestaBundle\Entity\EgwAccounts"** **Entity EgwAccounts :** ` /** * @ORM\OneToOne(targetEntity="EgwAddressbook", inversedBy="EgwAccounts") * @ORM\JoinColumn(name="account_id", referencedColumnName="account_id") * @ORM\Id */ protected $egwAddressbook; public function setEgwAddressbook(EgwAddressbook $egwAddressbook) { $this->egwAddressbook = $egwAddressbook; return $this; }` **entity EgwAddressbook :** ` /** * @ORM\OneToOne(targetEntity="EgwAccounts", mappedBy="EgwAddressbook") */ protected $egwAccounts; public function getEgwAccounts(EgwAccounts $egwAccounts) { return $this->egwAccounts; }`
Author
Owner

@denis75chine commented on GitHub (Jun 24, 2019):

no answer
stop mission... :(((

@denis75chine commented on GitHub (Jun 24, 2019): no answer stop mission... :(((
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6255