gpt4 book ai didi

mysql - Doctrine :架构:更新不更新数据库

转载 作者:行者123 更新时间:2023-11-29 22:09:55 25 4
gpt4 key购买 nike

无论我在我的实体中做出什么改变, Doctrine 似乎都没有更新它。我知道已经有一些类似的问题。我已经浏览过它们并尝试过:

php 应用程序/控制台缓存:清除php 应用程序/控制台 Doctrine :缓存:清除元数据

php 应用程序/控制台 Doctrine :schema:update --force

我从未导入过数据库,因此我的 src 文件夹中没有 orm.yaml 文件。

我正在使用 mysql 数据库和 symfony 以及作为 orm 的 Doctrine 。

这是我的配置

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.

我的实体是术语.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;
}

}

?>

最佳答案

如果您使用没有框架的 Doctrine (就像我一样),请删除对 Doctrine 作为 ORM 的调用(可能不需要)

use Doctrine\ORM\Mapping as ORM;

然后将所有 @ORM\ 替换为 @

这阻止了 Doctrine 承认类(Class)及其变化。希望对您有帮助

关于mysql - Doctrine :架构:更新不更新数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31780131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com