无论我在我的网站上做出什么样的改变,学说似乎都没有更新它。我知道已经有一些类似的问题了。我已经完成了它们并尝试过:
php app / console cache:clear php app / console doctrine:cache:clear-metadata
php app / console doctrine:schema:update --force
我从未导入数据库,因此我的src文件夹中没有orm.yaml文件。
我正在使用带有symfony和doctrine的mysql数据库作为orm。
这是我的配置
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
doctrine:schema:validate给我这个:
[Mapping] FAIL - The entity-class 'Madhuri\TermsBundle\Entity\RelatedTerm' mapping is invalid:
* The association Madhuri\TermsBundle\Entity\RelatedTerm#term1 refers to the inverse side field Madhuri\TermsBundle\Entity\Term#relatedTerm which does not exist.
我的实体是 Term.php
namespace Madhuri\TermsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Term
*
* @ORM\Table(name="terms")
* @ORM\Entity
*/
class Term
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="termName", type="string", length=255)
*/
private $termName;
/**
* @var string
*
* @ORM\Column(name="description", type="string", length=2000)
*/
private $description;
/**
* @var string
*
* @ORM\Column(name="mnemonic", type="string", length=2000)
*/
private $mnemonic;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="RelatedTerm",
* mappedBy="term1")
*/
private $relatedTerms;
// /**
// * @var ArrayCollection
// *
// * @ORM\OneToMany(targetEntity="TermExamples",
// * mappedBy="term")
// */
// private $termExamples;
public function __construct()
{
$this->relatedTerms = new ArrayCollection();
$this->$termExamples = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get Related Terms
*/
public function getRelatedTerms()
{
return $this->relatedTerms ;
}
/**
* Add related term
*/
public function addRelatedTerm($relatedTerm)
{
$this->relatedTerms[] = $relatedTerm;
}
/**
* Clear related Terms
*/
public function clearRelatedTerms()
{
$this->relatedTerms->clear();
}
/**
* Remove a related Term
*/
public function removeRelatedTerm($relatedTerm)
{
$this->relatedTerms->removeElement($relatedTerm);
}
/**
* Get Term Examples
*/
// public function getTermExamples()
// {
// return $this->termExamples ;
// }
//
// /**
// * Add term example
// */
// public function addTermExample($termExample)
// {
// $this->termExamples[] = $termExample;
// }
//
// /**
// * Clear term examples
// */
// public function clearTermExamples()
// {
// $this->termExamples->clear() ;
// }
//
// /**
// * Remove a Term Example
// */
// public function removeTermExample($termExample)
// {
// $this->termExamples->removeElement($termExample);
// }
/**
* Set termName
*
* @param string $termName
* @return Term
*/
public function setTermName($termName)
{
$this->termName = $termName;
return $this;
}
/**
* Get termName
*
* @return string
*/
public function getTermName()
{
return $this->termName;
}
/**
* Set description
*
* @param string $description
* @return Term
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set mnemonic
*
* @param string $mnemonic
* @return Term
*/
public function setMnemonic($mnemonic)
{
$this->mnemonic = $mnemonic;
return $this;
}
/**
* Get mnemonic
*
* @return string
*/
public function getMnemonic()
{
return $this->mnemonic;
}
}
RelatedTerm.php
<?php
namespace Madhuri\TermsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* RelatedTerms
*
* @ORM\Table(name="related_terms")
* @ORM\Entity
*/
class RelatedTerm
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var Term
*
* @ORM\ManyToOne(targetEntity="Term",
* inversedBy="relatedTerm")
*/
private $term1;
/**
* @var Term
*
* @ORM\ManyToOne(targetEntity ="Term")
*/
private $term2;
/**
* @var string
*
* @ORM\Column(name="notes", type="string", length=2000, nullable=true)
*/
private $notes;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get term1
*
* @return Term
*/
public function getTerm1()
{
if($this->term1)
{
return $this->term1;
}
else {
return null;
}
}
/**
* Set term1
*
* @param Term $term1
*
* @return Term
*/
public function setTerm1(Term $term1)
{
$this->term1 = $term1;
return $this;
}
/**
* Get term2
*
* @return Term
*/
public function getTerm2()
{
return $this->term2;
}
/**
* Set term2
*
* @param Term $term2
*
* @return Term
*/
public function setTerm2( Term $term2)
{
$this->term2 = $term2;
return $this;
}
/**
* Get notes
*
* @return string
*/
public function getNotes()
{
return $this->notes;
}
/**
* Set notes
*
* @param string $notes
*
* @return Term
*/
public function setNotes($notes)
{
$this->notes = $notes;
return $this;
}
}
?>
答案 0 :(得分:0)
如果您正在使用没有框架的学说(就像我一样),请将调用原则删除为ORM(可能不需要)
use Doctrine\ORM\Mapping as ORM;
然后将所有@ORM\
替换为@
。
这阻止了学说认识课程及其变化。 希望它有所帮助