为从 App\Entity\CINFO\CiRome 到 App\Entity\CINFO\CiFormacode 的关系引用的列名“FCO_ID”不存在
Column name `FCO_ID` referenced for relation from App\Entity\CINFO\CiRome towards App\Entity\CINFO\CiFormacode does not exist
我在尝试为 ManyToMany 关系生成 table 时遇到错误。
在这两个实体中,我有 ManyToMany 关系,当我使用 运行 make:migration 命令时,出现错误 'Column name FCO_ID
referenced for relation from App\Entity\CINFO\CiRome towards App\Entity\CINFO\CiFormacode does not exist'。
我不明白我做错了什么,这与学说文档中的完全一样。 https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/association-mapping.html#many-to-many-unidirectional.
我的id的名字不是'id',而是我在ManyToMany关系的JoinColumns中定义的
/**
* @ORM\Entity(repositoryClass=CiFormacodeRepository::class)
* @ORM\Table(name="ci_formacode", indexes={
* @Index(name="FCO_CODE", columns={"FCO_CODE"})
* })
*/
class CiFormacode
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer", name="FCO_ID")
*/
private $FCO_ID;
/**
* @ORM\ManyToOne(targetEntity=CiFormacode::class, inversedBy="ciFormacodes")
* @JoinColumn(name="FCO_PERE_ID", referencedColumnName="FCO_ID", nullable=true)
*/
private $FCO_PERE;
/**
* @ORM\ManyToMany(targetEntity=CiRome::class, mappedBy="FCO")
* @ORM\JoinTable(name="ci_fcorome", joinColumns={@JoinColumn(name="ROME_ID", referencedColumnName="rome_id")})
*/
private $ciRomes;
}
/**
* @ORM\Entity(repositoryClass=CiRomeRepository::class)
* @ORM\Table(name="ci_rome")
*/
class CiRome
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer", name="rome_id")
*/
private $rome_id;
/**
* @ORM\ManyToOne(targetEntity=CiRomeDp::class, inversedBy="ciRomes")
* @JoinColumn(name="romedp_id", referencedColumnName="romedp_id", nullable=true)
*/
private $romedp;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $rome_code;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $rome_lib;
/**
* @ORM\OneToMany(targetEntity=CiRomeAppelation::class, mappedBy="ROME")
*/
private $ciRomeAppelations;
/**
*
* @ManyToMany(targetEntity="App\Entity\CINFO\CiFormacode")
* @JoinTable(name="ci_fcorome",
* joinColumns={@JoinColumn(name="FCO_ID", referencedColumnName="FCO_ID")},
* inverseJoinColumns={@JoinColumn(name="rome_id", referencedColumnName="rome_id")}
* )
*/
private $FCO;
}
感谢您的帮助!
根据 @simon.ro 建议,我发现我在 JoinColumn 中犯了一个错误。
更正以下两个实体:
/**
* @ORM\Entity(repositoryClass=CiFormacodeRepository::class)
* @ORM\Table(name="ci_formacode", indexes={
* @Index(name="FCO_CODE", columns={"FCO_CODE"})
* })
*/
class CiFormacode
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer", name="FCO_ID")
*/
private $FCO_ID;
/**
* @ORM\ManyToOne(targetEntity=CiFormacode::class, inversedBy="ciFormacodes")
* @JoinColumn(name="FCO_PERE_ID", referencedColumnName="FCO_ID", nullable=true)
*/
private $FCO_PERE;
/**
* @ManyToMany(targetEntity="App\Entity\CINFO\CiRome")
* @JoinTable(name="ci_fcorome",
* joinColumns={@JoinColumn(name="FCO_ID", referencedColumnName="FCO_ID")},
* inverseJoinColumns={@JoinColumn(name="ROME_ID", referencedColumnName="rome_id")}
* )
*/
private $ciRomes;
}
在 CiFormacode 中,我反转了 id,你必须将实际实体的 id 放入 JoinColumn,并将要加入的实体的 id 放入 inverseJoinColumns。
实际上这更有意义。
第二次实体更正:
/**
* @ORM\Entity(repositoryClass=CiRomeRepository::class)
* @ORM\Table(name="ci_rome")
*/
class CiRome
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer", name="rome_id")
*/
private $rome_id;
/**
* @ORM\ManyToOne(targetEntity=CiRomeDp::class, inversedBy="ciRomes")
* @JoinColumn(name="romedp_id", referencedColumnName="romedp_id", nullable=true)
*/
private $romedp;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $rome_code;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $rome_lib;
/**
* @ORM\OneToMany(targetEntity=CiRomeAppelation::class, mappedBy="ROME")
*/
private $ciRomeAppelations;
/**
* @ManyToMany(targetEntity="App\Entity\CINFO\CiFormacode", mappedBy="ciRomes")
*/
private $FCO;
}
在 CiRome 中,您只需将变量“$FCO”映射到 'mappedBy' 即可获取对 CiFormacode 的引用。
谢谢你。
我在尝试为 ManyToMany 关系生成 table 时遇到错误。
在这两个实体中,我有 ManyToMany 关系,当我使用 运行 make:migration 命令时,出现错误 'Column name FCO_ID
referenced for relation from App\Entity\CINFO\CiRome towards App\Entity\CINFO\CiFormacode does not exist'。
我不明白我做错了什么,这与学说文档中的完全一样。 https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/association-mapping.html#many-to-many-unidirectional.
我的id的名字不是'id',而是我在ManyToMany关系的JoinColumns中定义的
/**
* @ORM\Entity(repositoryClass=CiFormacodeRepository::class)
* @ORM\Table(name="ci_formacode", indexes={
* @Index(name="FCO_CODE", columns={"FCO_CODE"})
* })
*/
class CiFormacode
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer", name="FCO_ID")
*/
private $FCO_ID;
/**
* @ORM\ManyToOne(targetEntity=CiFormacode::class, inversedBy="ciFormacodes")
* @JoinColumn(name="FCO_PERE_ID", referencedColumnName="FCO_ID", nullable=true)
*/
private $FCO_PERE;
/**
* @ORM\ManyToMany(targetEntity=CiRome::class, mappedBy="FCO")
* @ORM\JoinTable(name="ci_fcorome", joinColumns={@JoinColumn(name="ROME_ID", referencedColumnName="rome_id")})
*/
private $ciRomes;
}
/**
* @ORM\Entity(repositoryClass=CiRomeRepository::class)
* @ORM\Table(name="ci_rome")
*/
class CiRome
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer", name="rome_id")
*/
private $rome_id;
/**
* @ORM\ManyToOne(targetEntity=CiRomeDp::class, inversedBy="ciRomes")
* @JoinColumn(name="romedp_id", referencedColumnName="romedp_id", nullable=true)
*/
private $romedp;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $rome_code;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $rome_lib;
/**
* @ORM\OneToMany(targetEntity=CiRomeAppelation::class, mappedBy="ROME")
*/
private $ciRomeAppelations;
/**
*
* @ManyToMany(targetEntity="App\Entity\CINFO\CiFormacode")
* @JoinTable(name="ci_fcorome",
* joinColumns={@JoinColumn(name="FCO_ID", referencedColumnName="FCO_ID")},
* inverseJoinColumns={@JoinColumn(name="rome_id", referencedColumnName="rome_id")}
* )
*/
private $FCO;
}
感谢您的帮助!
根据 @simon.ro 建议,我发现我在 JoinColumn 中犯了一个错误。
更正以下两个实体:
/**
* @ORM\Entity(repositoryClass=CiFormacodeRepository::class)
* @ORM\Table(name="ci_formacode", indexes={
* @Index(name="FCO_CODE", columns={"FCO_CODE"})
* })
*/
class CiFormacode
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer", name="FCO_ID")
*/
private $FCO_ID;
/**
* @ORM\ManyToOne(targetEntity=CiFormacode::class, inversedBy="ciFormacodes")
* @JoinColumn(name="FCO_PERE_ID", referencedColumnName="FCO_ID", nullable=true)
*/
private $FCO_PERE;
/**
* @ManyToMany(targetEntity="App\Entity\CINFO\CiRome")
* @JoinTable(name="ci_fcorome",
* joinColumns={@JoinColumn(name="FCO_ID", referencedColumnName="FCO_ID")},
* inverseJoinColumns={@JoinColumn(name="ROME_ID", referencedColumnName="rome_id")}
* )
*/
private $ciRomes;
}
在 CiFormacode 中,我反转了 id,你必须将实际实体的 id 放入 JoinColumn,并将要加入的实体的 id 放入 inverseJoinColumns。 实际上这更有意义。
第二次实体更正:
/**
* @ORM\Entity(repositoryClass=CiRomeRepository::class)
* @ORM\Table(name="ci_rome")
*/
class CiRome
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer", name="rome_id")
*/
private $rome_id;
/**
* @ORM\ManyToOne(targetEntity=CiRomeDp::class, inversedBy="ciRomes")
* @JoinColumn(name="romedp_id", referencedColumnName="romedp_id", nullable=true)
*/
private $romedp;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $rome_code;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $rome_lib;
/**
* @ORM\OneToMany(targetEntity=CiRomeAppelation::class, mappedBy="ROME")
*/
private $ciRomeAppelations;
/**
* @ManyToMany(targetEntity="App\Entity\CINFO\CiFormacode", mappedBy="ciRomes")
*/
private $FCO;
}
在 CiRome 中,您只需将变量“$FCO”映射到 'mappedBy' 即可获取对 CiFormacode 的引用。
谢谢你。