2
我一個事實真在實體後,我其實架構更新--force幾個屬性和當我實際上添加數據庫中的數據存在,我覺得這是錯誤唯一真正的限制是不是行之有效
SQLSTATE [23000]:完整性約束違規:1062重複條目 '1' 關鍵 'UNIQ_101C7E5A6C6E55B5'
代碼實體:
<?php
namespace test\MedBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* Apps
*
* @ORM\Table(name="apps",uniqueConstraints={@ORM\UniqueConstraint(columns={"nom", "prenom","age","class"})}
)
* @ORM\Entity(repositoryClass="test\MedBundle\Repository\AppsRepository")
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity(fields={"nom","prenom","class","age"}, message="Cette champ existe déja.")
*/
class Apps
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=255, unique=true)
*/
private $nom;
/**
* @var string
*
* @ORM\Column(name="class", type="string", length=255, unique=true)
*/
private $class;
/**
* @var string
*
* @ORM\Column(name="prenom", type="string", length=255, unique=true)
*/
private $prenom;
/**
* @var string
*
* @ORM\Column(name="age", type="string", length=255, unique=true)
*/
private $age;
/**
* @ORM\Column(type="string", length=255)
*/
public $path;
/**
* @Assert\File(maxSize="6000000")
*/
private $file;
/**
* @ORM\ManyToOne(targetEntity="Med",inversedBy="apps")
* @ORM\JoinColumn(name="id_med", referencedColumnName="id",nullable=true)
*/
private $med;
/**
* @ORM\OneToMany(targetEntity="test\MedBundle\Entity\Affichage",mappedBy="apps")
*/
private $comment;
/**
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(name="nbr_modif", type="string", nullable=true)
*/
private $unbr_modif;
/**
* @ORM\PreUpdate
*/
public function nbremodif() {
$this->setUnbrModif($this->unbr_modif+1);
}
}
我控制器
public function addAction() {
$em = $this->getDoctrine()->getManager();
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$x= $request->request->get('k');
for($i=1;$i<=$x;$i++){
$nom = $request->request->get('nom'.$i);
$prenom = $request->request->get('prenom'.$i);
$age = $request->request->get('age'.$i);
$class = $request->request->get('sexe'.$i);
$cop = new Apps();
$cop->setAge($age);
$cop->setNom($nom);
$cop->setPrenom($prenom);
$cop->setClass($class);
$cop->setPath("path test");
$em->persist($cop);
$em->flush();
}
} //end for
return $this->render('MedBundle:Apps:form.html.twig');
}
是什麼時,他說,我們看到警報的消息告訴他,這個數據已經存在於數據庫中的數據
同樣的問題我的朋友 這就是我現在發現 SQLSTATE [23000]:完整性約束違規:1062 Duplicata杜冠軍「1-1 -1-1'pour la clef'UNIQ_101C7E5A6C6E55B5A625945BA13010B2ED4B199F' –
這不完全是同一個問題;)你如何在控制器中綁定和驗證你的表單? – goto
代碼我的控制器: http://pastebin.com/LgDCRatq –