때 가지고 내가 내 데이터베이스를 업데이트하려고하면 오류 :교리, ralation의 ManyToOne
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
symfony
.#sql-d8c_55
, CONSTRAINTFK_957A6479A233CB39
FOREIGN KEY (klient_id
) REFERENCESklient
(id
))
내 클래스 사용자 :
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* Class User
* @package AppBundle\Entity
*
* @ORM\Table("fos_user")
* @ORM\Entity()
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Klient", inversedBy="users")
* @ORM\JoinColumn(nullable=false)
*/
private $klient;
/**
* @return mixed
*/
public function getKlient()
{
return $this->klient;
}
/**
* @param mixed $klient
*/
public function setKlient($klient)
{
$this->klient = $klient;
}
public function __construct()
{
parent::__construct();
}
}
클래스 Klient 내 의견
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Klient
*
* @ORM\Table(name="klient")
* @ORM\Entity(repositoryClass="AppBundle\Repository\KlientRepository")
*/
class Klient
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="nazwa", type="string", length=255, unique=true)
*/
private $nazwa;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\User", mappedBy="klient")
*/
private $users;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set nazwa
*
* @param string $nazwa
*
* @return Klient
*/
public function setNazwa($nazwa)
{
$this->nazwa = $nazwa;
return $this;
}
/**
* Get nazwa
*
* @return string
*/
public function getNazwa()
{
return $this->nazwa;
}
public function __construct()
{
$this->users = new ArrayCollection();
}
}
하시기 바랍니다한다 이러한 엔티티를 지속시키는 것과 관련된 나머지 코드를 보여줍니다. Doctrine은 자동으로 관계를 유지하지 않으므로 (그렇게하도록 구성된 경우는 제외), 그 원인이 될 수 있지만 그 코드를 추가 할 때 더 많이 알 수 있습니다. –
좋아요, 내 게시물을 편집합니다 – pierzcha
엔티티를 실제로 유지하는 코드는 무엇입니까? 엔티티 클래스를 볼 수는 있지만 아무것도하지 않습니다. –