Php 条令';他工作不正常

Php 条令';他工作不正常,php,sql,symfony,doctrine-orm,doctrine,Php,Sql,Symfony,Doctrine Orm,Doctrine,我试图让一个多人协会在教义中发挥作用,但运气不好,以下是我的关系准则: // the entity : Product /** * @Id * @ManyToOne(targetEntity="ProductsModule\Entity\Configuration", inversedBy="product") * @JoinColumns={@JoinColumn(name="id_type", referencedColumnName="id"), *

我试图让一个多人协会在教义中发挥作用,但运气不好,以下是我的关系准则:

// the entity : Product

/**
 * @Id
 * @ManyToOne(targetEntity="ProductsModule\Entity\Configuration", inversedBy="product")
 * @JoinColumns={@JoinColumn(name="id_type", referencedColumnName="id"),
 *               @JoinColumn(name="id_site", referencedColumnName="id")}
 */
private $configurations;

/**
 * @Id
 * @ManyToOne(targetEntity="ProductsModule\Entity\Picture", inversedBy="product")
 * @JoinColumn(name="id_picture", referencedColumnName="id")
 */
private $picture;
与之相反的是:

// the entity : Configuration

/**
 * @OneToMany(targetEntity="ProductsModule\Entity\Product", mappedBy="configurations")
 */
private $product;

// the code in the controller
$product = new Product;
$product->setConfiguration($configuration); // the configuration object is retrieved from DB
$product->setPicture($picture);
$this->em->persist($product);
try
{
    $this->em->flush();
}
catch (\Exception $e)
{
    var_dump($e->getMessage());die();
}
问题在于,条令试图设置JoinColumn的第一列(在上面的示例中为:id_type),但忽略了第二列,这会引发以下错误:

An exception occurred while executing 'INSERT INTO tableX (id_picture, id_type) VALUES (?, ?)' with params [1, 1]:SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`db`.`tableX`, CONSTRAINT `fk2` FOREIGN KEY (`id_site`) REFERENCES `sites` (`id`))
产品实体本身是一个从多个关系中诞生的实体(这就是为什么它有两个主键),我只是更改了实体的名称以保持代码的私密性,因为我不允许共享它


谢谢。

您似乎已使用与站点属性相关的外键尝试使用以下内容更新架构:

app/console doctrine:schema:update --force 
如果出现相同错误,请尝试删除表或数据库如果这不会产生任何问题,请确保导出数据库的sql文件并删除所有外键,导入数据,然后重新执行命令:
app/console原则:schema:update--force

您是否尝试在关系关联中使用
cascade={“persist”,“update”}