【发布时间】:2020-08-14 23:10:23
【问题描述】:
在我的代码中,一个班级有很多学生。每个学生只有一个班级。
我正在尝试使用 php bin/console doctrine:schema:update --force 更新我的数据库架构
但我一直收到同样的错误:
列名
id为来自 App\Entity\Students 的关系引用 对 App\Entity\Classes 不存在。
我该如何解决?
学生班:
<?php
namespace App\Entity;
use App\Repository\StudentsRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=StudentsRepository::class)
*/
class Students
{
/**
* @ORM\id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $studentID;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Classes", inversedBy="students")
*/
private $classe;
public function getclasse(): ?Classes
{
return $this->classe;
}
public function setclasse(?Classes $classe): self
{
$this->classes = $classe;
return $this;
}
public function getstudentID(): ?int
{
return $this->studentID;
}
}
类类:
<?php
namespace App\Entity;
use App\Repository\ClassesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ClassesRepository::class)
*/
class Classes
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $classID;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Students", mappedBy="classe")
*/
private $students;
public function __construct()
{
$this->students = new ArrayCollection();
}
/**
* @return Collection/Students[]
*/
public function getstudents(): Collection
{
return $this->students;
}
【问题讨论】:
标签: php database symfony doctrine