When i tried to update my database i got this error:
i'm not sure but I think the error means that the value for column tva_id on table fly
you are inserting doesn't exist on table tva. when i check in phpmyadmin tva(
id)) should be link to
(tva_id
)` in table Post but is not. what should i do to fix this error ?
[Doctrine\DBAL\DBALException]
An exception occurred while executing 'ALTER TABLE post ADD CONSTRAINT FK_5 A8A6C8D4D79775F FOREIGN KEY (tva_id) REFERENCES tva (id)':
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (fly
.#sql-93c_155
, CONSTRAI NTFK_5A8A6C8D4D79775F
FOREIGN KEY (tva_id
) REFERENCEStva
(id
))
Tva.php
<?php
namespace FLY\BookingsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Tva
*
* @ORM\Table("tva")
* @ORM\Entity(repositoryClass="FLY\BookingsBundle\Entity\TvaRepository")
*/
class Tva
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var float
*
* @ORM\Column(name="multiplicate", type="float")
*/
private $multiplicate;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=125)
*/
private $name;
/**
* @var float
*
* @ORM\Column(name="value", type="float")
*/
private $value;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set multiplicate
*
* @param float $multiplicate
* @return Tva
*/
public function setMultiplicate($multiplicate)
{
$this->multiplicate = $multiplicate;
return $this;
}
/**
* Get multiplicate
*
* @return float
*/
public function getMultiplicate()
{
return $this->multiplicate;
}
/**
* Set name
*
* @param string $name
* @return Tva
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set value
*
* @param float $value
* @return Tva
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* Get value
*
* @return float
*/
public function getValue()
{
return $this->value;
}
}
post.php
<?php
namespace FLY\BookingsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Application\Sonata\UserBundle\Entity\User;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use JMS\SecurityExtraBundle\Annotation\Secure;
/**
* Post
*
* @ORM\Table(name="post")
* @ORM\Entity(repositoryClass="FLY\BookingsBundle\Entity\PostRepository")
*/
class Post
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="FLY\BookingsBundle\Entity\Tva", cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=false)
*/
private $tva;
/**
*
*
* @ORM\ManyToOne(targetEntity="Application\Sonata\UserBundle\Entity\User")
* @ORM\JoinColumn(onDelete="CASCADE")
* @Security("user.getId() == post.getOwner()")
*/
private $owner;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @return User
*/
public function getOwner()
{
return $this->owner;
}
/*
* @param User $owner
*/
public function setOwner(User $owner)
{
$this->owner = $owner;
return $this;
}
/**
* Set tva
*
* @param \FLY\BookingsBundle\Entity\Tva $tva
* @return Post
*/
public function setTva(\FLY\BookingsBundle\Entity\Tva $tva)
{
$this->tva = $tva;
return $this;
}
/**
* Get tva
*
* @return \FLY\BookingsBundle\Entity\Tva
*/
public function getTva()
{
return $this->tva;
}
}
user.php
<?php
namespace Application\Sonata\UserBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
use ArrayIterator;
use Closure;
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
/**
* This file has been generated by the Sonata EasyExtends bundle ( http://sonata-project.org/easy-extends )
*
*/
/**
* @ORM\Entity(repositoryClass="FLY\UserBundle\Repository\UserRepository")
* @ORM\Table(name="fos_user_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
$this->commandes = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @ORM\OneToMany(targetEntity="FLY\BookingsBundle\Entity\Commandes", mappedBy="user", cascade={"remove"})
* @ORM\JoinColumn(nullable=true)
*/
private $commandes;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Add commandes
*
* @param \FLY\BookingsBundle\Entity\Commandes $commandes
* @return User
*/
public function addCommande(\FLY\BookingsBundle\Entity\Commandes $commandes)
{
$this->commandes[] = $commandes;
return $this;
}
/**
* Remove commandes
*
* @param \FLY\BookingsBundle\Entity\Commandes $commandes
*/
public function removeCommande(\FLY\BookingsBundle\Entity\Commandes $commandes)
{
$this->commandes->removeElement($commandes);
}
/**
* Get commandes
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCommandes()
{
return $this->commandes;
}
}