我尝试用doctrine管理我的数据库。
我有两个实体voiture et modele,我在3h后成功添加了modele。当我对实体voiture
进行编码时,它会一直显示基础已更新且没有变化。
我的模式代码:
<?php
/**
* Created by PhpStorm.
* User: jamel_pc
* Date: 2016-11-27
* Time: 9:16 PM
*/
namespace ParcBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Modele
* @package ParcBundle\Entity
*
* @ORM\Entity
* @ORM\Table(name="Modele")
*/
class Modele{
/**
*@ORM\Id
*@ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string",length=255)
*
*/
private $Libelle;
/**
* @ORM\Column(type="string",length=255)
*/
private $Pays;
/**
* @ORM\Column(type="string",length=255)
*/
/**
* @return mixed
*/
public function getLibelle()
{
return $this->Libelle;
}
/**
* @param mixed $Libelle
*/
public function setLibelle($Libelle)
{
$this->Libelle = $Libelle;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return mixed
*/
public function getPays()
{
return $this->Pays;
}
/**
* @param mixed $Pays
*/
public function setPays($Pays)
{
$this->Pays = $Pays;
}
}
和我的声音代码:
<?php
/**
* Created by PhpStorm.
* User: jamel_pc
* Date: 2016-11-27
* Time: 11:10 PM
*/
/**
* Class voiture
* @package ParcBundle\Entity
*
* @ORM\Entity
* @ORM\Table(name="Voiture")
*/
namespace ParcBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
class voiture
{
/**
*@ORM\Id
*@ORM\Column(type="integer")
*/
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string",length=255)
*
*/
private $Serie;
/**
* @ORM\Column(type="datetime",length=255)
*/
private $DateMiseCirculation;
/**
* @ORM\Column(type="string",length=255)
*/
private $Marque;
/**
* @ORM\ManyToOne(targetEntity="ParcBundle\Entity\Modele" )
* @ORM\JoinColumn(name="id", referencedColumnName="id");
*/
private $modele;
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return mixed
*/
public function getModele()
{
return $this->modele;
}
/**
* @param mixed $modele
*/
public function setModele($id)
{
$this->modele = $modele;
}
/**
* @return mixed
*/
public function getSerie()
{
return $this->Serie;
}
/**
* @param mixed $Serie
*/
public function setSerie($Serie)
{
$this->Serie = $Serie;
}
/**
* @return mixed
*/
public function getDateMiseCirculation()
{
return $this->DateMiseCirculation;
}
/**
* @param mixed $DateMiseCirculation
*/
public function setDateMiseCirculation($DateMiseCirculation)
{
$this->DateMiseCirculation = $DateMiseCirculation;
}
/**
* @return mixed
*/
public function getMarque()
{
return $this->Marque;
}
/**
* @param mixed $Marque
*/
public function setMarque($Marque)
{
$this->Marque = $Marque;
}
}
这是我得到的错误:
错误:无法更新 - 您的数据库已经与之同步 当前实体元数据。
答案 0 :(得分:0)
您有两个id字段注释。删除其中一个:
/**
*@ORM\Id
*@ORM\Column(type="integer")
*/
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
答案 1 :(得分:0)
可能是因为您在将其用于实体注释后导入ORM
。
尝试将您的实体注释放在下面,使用use Doctrine\ORM\Mapping as ORM
,如下所示:
<?php
/**
* Created by PhpStorm.
* User: jamel_pc
* Date: 2016-11-27
* Time: 11:10 PM
*/
namespace ParcBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class voiture
* @package ParcBundle\Entity
*
* @ORM\Entity
* @ORM\Table(name="Voiture")
*/
class voiture
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/.../
}