gpt4 book ai didi

mysql - Symfony Doctrine 无法创建外键

转载 作者:行者123 更新时间:2023-11-29 12:14:23 25 4
gpt4 key购买 nike

表中的字段Ordertaxi:

@ORM\Column(name="custom_id", type="integer", options={"unsigned"=true})
private $customId;

// new "column", which i want to add
@ORM\OneToOne(targetEntity="CustomOrder")
private $custom;

表中的字段CustomOrder:

@ORM\Column(name="id", type="integer")
@ORM\Id
@ORM\GeneratedValue(strategy="AUTO")
private $id;
<小时/>

执行:

php app/console doctrine:schema:update --dump-sql

获取:

ALTER TABLE Ordertaxi ADD CONSTRAINT FK_D345B7FB614A603A FOREIGN KEY (custom_id) REFERENCES CustomOrder (id);
CREATE UNIQUE INDEX UNIQ_D345B7FB614A603A ON Ordertaxi (custom_id)

执行:

php app/console doctrine:schema:update --force

获取:

[Doctrine\DBAL\DBALException]                                                                                                                       
An exception occurred while executing 'ALTER TABLE Ordertaxi ADD CONSTRAINT FK_D345B7FB614A603A FOREIGN KEY (custom_id) REFERENCES CustomOrder (id
)':
SQLSTATE[HY000]: General error: 1005 Can't create table 'aerotaxi.#sql-3b8a_4c' (errno: 150)

为什么这个查询会导致错误?

最佳答案

将此代码添加到 Ordertaxi

@JoinColumn(name="customOrder_id", referencedColumnName="id")

关于mysql - Symfony Doctrine 无法创建外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30081924/

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