gpt4 book ai didi

Symfony - SQLSTATE-23000 : Integrity constraint violation: 1022 Can't write duplicate key

转载 作者:行者123 更新时间:2023-12-05 06:36:08 25 4
gpt4 key购买 nike

我想在我的 Doctrine Product、ProductType 和 Manufacturer 实体中使用关系,但是当我执行 php bin/console doctrine:migrations:migrate 时,我收到此错误:

-> ALTER TABLE product ADD CONSTRAINT FK_D34A04ADA23B42D FOREIGN KEY (manufacturer_id) REFERENCES manufacturer (id)
Migration 20180223095324 failed during Execution. Error An exception occurred while executing 'ALTER TABLE product ADD CONSTRAINT FK_D34A04ADA23B42D FOREIGN KEY (manufacturer_id) REFERENCES manufacturer (id)':

SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table '#sql-36a_f'

这是我在产品实体中的关系:

/**
* @ORM\ManyToOne(targetEntity="App\Entity\ProductType", inversedBy="products")
* @ORM\JoinColumn(name="type_id", referencedColumnName="id", nullable=true)
*/
private $type;

/**
* @ORM\ManyToOne(targetEntity="App\Entity\Manufacturer", inversedBy="products")
* @ORM\JoinColumn(name="manufacturer_id", referencedColumnName="id", nullable=true)
*/
private $manufacturer;

我的 ProductType 实体:

/**
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="type")
*/
private $products;

/**
* @return Collection|Product[]
*/
public function getProducts()
{
return $this->products;
}

public function __construct()
{
$this->products = new ArrayCollection();
}

我的制造商实体:

/**
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="manufacturer")
*/
private $products;

/**
* @return Collection|Product[]
*/
public function getProducts()
{
return $this->products;
}

public function __construct()
{
$this->products = new ArrayCollection();
}

我可以在一个实体中使用多个关系吗?或者我可以重命名外键吗?

最佳答案

您必须通过以下方式更新方案:bin/console doctrine:schema:update

关于Symfony - SQLSTATE-23000 : Integrity constraint violation: 1022 Can't write duplicate key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49274214/

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