SQLSTATE[42S22]:找不到列:1054 Champ 't0.id' inconnu dans where 子句 ( Symfony 5 , API Platform )



我有两个类,class Child"Livruer";从类父继承";用户"。API Plateform插入后返回数据时出现问题。(它成功插入,但数据没有返回+没有插入到表Users中,在此之前它插入到Users+Livreur中,但现在没有(。

类";用户";(父级(:

<?php
namespace AppEntity;
use ApiPlatformCoreAnnotationApiResource;
use AppRepositoryUsersRepository;
use DoctrineORMMapping as ORM;
use DoctrineORMMapping ;
use SymfonyComponentSecurityCoreUserUserInterface;
use SymfonyComponentSerializerAnnotationGroups;
use SymfonyComponentValidatorConstraints as Assert;
/**
* @ORMEntity(repositoryClass=UsersRepository::class)
* @ApiResource(
*     normalizationContext={"groups"={"read"}},
*     collectionOperations={"post"={},"get"={}},
*     itemOperations={"get","put"={"denormalization_Context"={"groups"={"put"}}}}
* )
*/
class Users implements UserInterface
{
/**
* @ORMId
* @ORMGeneratedValue
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=180)
* @Groups({"read"})
*/
private $email;
/**
* @AssertNotBlank()
* @ORMColumn(type="string", length=255)
* @Groups({"read"})
* @Groups({"put"})
*/
private $password;
/**
* @AssertNotBlank()
* @AssertExpression("this.getPassword() == this.getRepassword()",message="Mot de pass doit etre le meme dans les 2 deux champs")
*/
private $repassword;
/**
* @AssertNotBlank()
* @ORMColumn(type="string", length=30)
* @Groups({"read"})
* @Groups({"put"})
*/
private $username;
/**
* @AssertNotBlank()
* @ORMColumn(type="text")
* @Groups({"read"})
* @Groups({"put"})
*/
private $roles;
/**
* @AssertNotBlank()
* @ORMColumn(type="string", length=20)
* @Groups({"read"})
*/
private $cin;
/**
* @AssertNotBlank()
* @ORMColumn(type="string", length=20)
* @Groups({"read"})
*/
private $nom;
/**
* @AssertNotBlank()
* @ORMColumn(type="string", length=20)
* @Groups({"read"})
*/
private $prenom;
/**
* @AssertNotBlank()
* @ORMColumn(type="date")
* @Groups({"read"})
*/
private $dtn;
/**
* @AssertNotBlank()
* @ORMColumn(type="string", length=255, nullable=true)
* @Groups({"read"})
*/
private $dtype;
/**
* @AssertNotBlank()
* @ORMColumn(type="string", length=255, nullable=true)
* @Groups({"read"})
*/
private $img;
/**
* @AssertNotBlank()
* @ORMColumn(type="string", length=30, nullable=true)
* @Groups({"read"})
* @Groups({"put"})
*/
private $rib;
/**
* @ORMColumn(type="string", length=255, nullable=true)
* @Groups({"read"})
* @Groups({"put"})
*/
private $adresse;
/**
* @AssertNotBlank()
* @ORMColumn(type="string", length=20)
* @Groups({"read"})
* @Groups({"put"})
*/
private $tel;
protected function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getRoles(): array
{
return array('ROLE_USER');
}
public function setRoles(string $roles): self
{
$this->roles = $roles;
return $this;
}
public function getCin(): ?string
{
return $this->cin;
}
public function setCin(string $cin): self
{
$this->cin = $cin;
return $this;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getPrenom(): ?string
{
return $this->prenom;
}
public function setPrenom(string $prenom): self
{
$this->prenom = $prenom;
return $this;
}
public function getDtn(): ?DateTimeInterface
{
return $this->dtn;
}
public function setDtn(DateTimeInterface $dtn): self
{
$this->dtn = $dtn;
return $this;
}
public function getDtype(): ?string
{
return $this->dtype;
}
public function setDtype(?string $dtype): self
{
$this->dtype = $dtype;
return $this;
}
public function getImg(): ?string
{
return $this->img;
}
public function setImg(?string $img): self
{
$this->img = $img;
return $this;
}
public function getRib(): ?string
{
return $this->rib;
}
public function setRib(?string $rib): self
{
$this->rib = $rib;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(?string $adresse): self
{
$this->adresse = $adresse;
return $this;
}
public function getTel(): ?string
{
return $this->tel;
}
public function setTel(string $tel): self
{
$this->tel = $tel;
return $this;
}
public function getSalt()
{
// TODO: Implement getSalt() method.
}
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
public function getRepassword()
{
return $this->repassword;
}
public function setRepassword($repassword): void
{
$this->repassword = $repassword;
}
}

利夫鲁尔班(儿童(:

<?php
namespace AppEntity;
use AppRepositoryLivreurRepository;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineCommonCollectionsCollection;
use DoctrineORMMapping as ORM;
use ApiPlatformCoreAnnotationApiResource;
/**
* @ORMEntity(repositoryClass=LivreurRepository::class)
* @ApiResource()
*/
class Livreur extends Users
{
/**
* @ORMId
* @ORMGeneratedValue
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=20)
*/
private $type_vehicule;
/**
* @ORMColumn(type="string", length=20)
*/
private $permis;
/**
* @ORMColumn(type="boolean")
*/
private $disponibilite;
/**
* @ORMColumn(type="float")
*/
private $coffre;
/**
* @ORMColumn(type="text", nullable=true)
*/
private $log;
/**
* @ORMOneToMany(targetEntity=Commande::class, mappedBy="livreur")
*/
private $commandes;
/**
* @ORMOneToMany(targetEntity=Conge::class, mappedBy="livreur")
*/
private $conges;
/**
* @ORMManyToOne(targetEntity=Agence::class, inversedBy="livreurs")
* @ORMJoinColumn(nullable=false)
*/
private $agence;
/**
* @ORMOneToOne(targetEntity=SalaireEmp::class, inversedBy="livreur", cascade={"persist", "remove"})
*/
private $salaire_emp;
/**
* @ORMManyToOne(targetEntity=Ville::class, inversedBy="livreurs")
* @ORMJoinColumn(nullable=false)
*/
private $ville;
public function __construct()
{
$this->commandes = new ArrayCollection();
$this->conges = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTypeVehicule(): ?string
{
return $this->type_vehicule;
}
public function setTypeVehicule(string $type_vehicule): self
{
$this->type_vehicule = $type_vehicule;
return $this;
}
public function getPermis(): ?string
{
return $this->permis;
}
public function setPermis(string $permis): self
{
$this->permis = $permis;
return $this;
}
public function getDisponibilite(): ?int
{
return $this->disponibilite;
}
public function setDisponibilite(int $disponibilite): self
{
$this->disponibilite = $disponibilite;
return $this;
}
public function getCoffre(): ?float
{
return $this->coffre;
}
public function setCoffre(float $coffre): self
{
$this->coffre = $coffre;
return $this;
}
public function getLog(): ?string
{
return $this->log;
}
public function setLog(?string $log): self
{
$this->log = $log;
return $this;
}
/**
* @return Collection|Commande[]
*/
public function getCommandes(): Collection
{
return $this->commandes;
}
public function addCommande(Commande $commande): self
{
if (!$this->commandes->contains($commande)) {
$this->commandes[] = $commande;
$commande->setLivreur($this);
}
return $this;
}
public function removeCommande(Commande $commande): self
{
if ($this->commandes->removeElement($commande)) {
// set the owning side to null (unless already changed)
if ($commande->getLivreur() === $this) {
$commande->setLivreur(null);
}
}
return $this;
}
/**
* @return Collection|Conge[]
*/
public function getConges(): Collection
{
return $this->conges;
}
public function addConge(Conge $conge): self
{
if (!$this->conges->contains($conge)) {
$this->conges[] = $conge;
$conge->setLivreur($this);
}
return $this;
}
public function removeConge(Conge $conge): self
{
if ($this->conges->removeElement($conge)) {
// set the owning side to null (unless already changed)
if ($conge->getLivreur() === $this) {
$conge->setLivreur(null);
}
}
return $this;
}
public function getAgence(): ?Agence
{
return $this->agence;
}
public function setAgence(?Agence $agence): self
{
$this->agence = $agence;
return $this;
}
public function getSalaireEmp(): ?SalaireEmp
{
return $this->salaire_emp;
}
public function setSalaireEmp(?SalaireEmp $salaire_emp): self
{
$this->salaire_emp = $salaire_emp;
return $this;
}
public function getVille(): ?Ville
{
return $this->ville;
}
public function setVille(?Ville $ville): self
{
$this->ville = $ville;
return $this;
}
}

看起来您忘记设置继承映射策略了。这里有一个例子:

// (..)
/**
* @ORMEntity(repositoryClass=UsersRepository::class)
* @ORMInheritanceType("JOINED")
* @ORMDiscriminatorColumn(name="discr", type="string")
* @ORMDiscriminatorMap({"users" = "Users", "livreur" = "Livreur"})
* @ApiResource(
*     normalizationContext={"groups"={"read"}},
*     collectionOperations={"post"={},"get"={}},
*     itemOperations={"get","put"={"denormalization_Context"={"groups"={"put"}}}}
* )
*/
class Users implements UserInterface
{
// (..)

这将增加一个额外的字段";discr";到两个类的表,因此您必须更新它们的表配置,例如:

bin/console doctrine:schema:update --force

或者如果您使用迁移:

bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate

有关映射策略及其替代方案的解释,请参阅doctrine-project.org 上的继承映射页面

最新更新