gpt4 book ai didi

php - 如何在Cakephp3复合主键中插入空记录?

转载 作者:行者123 更新时间:2023-11-29 20:59:42 25 4
gpt4 key购买 nike

我的receed_po_details表有3个主键received_po_id、product_id、product_serial。有时,product_serial 有值(value),有时则毫无值(value)

如果product_serial为空,cakephp3不允许我插入记录

错误

Cannot insert row, some of the primary key values are missing. Got (12, 1, ), expecting (received_po_id, product_id, product_serial)

sql表

CREATE TABLE IF NOT EXISTS `received_po_details` (
`received_po_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`quantity_received` int(11) NOT NULL,
`product_serial` varchar(255),
PRIMARY KEY (received_po_id, product_id, product_serial),
FOREIGN KEY received_po_key (received_po_id) REFERENCES received_pos(id),
FOREIGN KEY product_key (product_id) REFERENCES products(id),
UNIQUE KEY received_po_detail_key (received_po_id, product_id, product_serial)
);

请注意,product_serial 只是一个值。它不是外键

实体-receedPoDetail.php

protected $_accessible = [
'*' => true,
'received_po_id' => true,
'product_id' => true,
'product_serial' => true,
];

Controller

$receivedPo = $this->ReceivedPos->patchEntity($receivedPo, $this->request->data);

请求数据打印

Array
(
[purchase_order_id] => 1
[depot_id] => 1
[prepared_by_id] =>
[approved_by_id] =>
[date_registration] => Array
(
[year] => 2016
[month] => 05
[day] => 20
[hour] => 03
[minute] => 45
)

[comment] =>
[received_po_status_id] => 2
[received_po_details] => Array
(
[0] => Array
(
[product_id] => 1
[quantity_received] => 100
[product_serial] =>
)

[1] => Array
(
[product_id] => 2
[quantity_received] => 1
[product_serial] => random_serial_here
)

[2] => Array
(
[product_id] => 3
[quantity_received] => 300
[product_serial] =>
)

)

)

谢谢

最佳答案

我认为您应该将product_serial的默认值设置为null应该是这样的..

  `product_serial` varchar(255) DEFAULT NULL,

关于php - 如何在Cakephp3复合主键中插入空记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37338097/

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