Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP 3不提交伪造键字段值_Cakephp - Fatal编程技术网

CakePHP 3不提交伪造键字段值

CakePHP 3不提交伪造键字段值,cakephp,Cakephp,我有以下两个表,以及从 bin/cake bake all clients bin/cake bake all clients_address 当我尝试添加一个地址时,将client_id设置为1,会出现以下错误 Error: SQLSTATE[HY000]: General error: 1364 Field 'client_id' doesn't have a default value If you are using SQL keywords as table column name

我有以下两个表,以及从

bin/cake bake all clients
bin/cake bake all clients_address
当我尝试添加一个地址时,将client_id设置为1,会出现以下错误

Error: SQLSTATE[HY000]: General error: 1364 Field 'client_id' doesn't have a default value

If you are using SQL keywords as table column names, you can enable identifier quoting for your database connection in config/app.php.

SQL Query:

INSERT INTO clients_address (address_line_1, address_line_2, address_line_3, town, county, postcode, email, tel, contact_name, default_address) VALUES (:c0, :c1, :c2, :c3, :c4, :c5, :c6, :c7, :c8, :c9)
是否需要一些额外的代码来获取要提交的客户端id

CREATE TABLE `clients` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
);

CREATE TABLE `clients_address` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `address_line_1` varchar(30) NOT NULL,
    `address_line_2` varchar(30) NOT NULL,
    `address_line_3` varchar(30) NOT NULL,
    `town` varchar(30) NOT NULL,
    `county` varchar(30) NOT NULL,
    `postcode` varchar(8) NOT NULL,
    `email` varchar(50) NOT NULL,
    `tel` varchar(13) NOT NULL,
    `contact_name` varchar(40) NOT NULL,
    `client_id` int(11) NOT NULL,
    `default_address` BOOLEAN NOT NULL DEFAULT 0,
        FOREIGN KEY (client_id) REFERENCES clients(id),
    PRIMARY KEY (`id`)
);
INSERT INTO `clients` (`id`, `name`) VALUES (1, 'First Client');
在客户机\地址表架构中,客户机\ id int11不为空,设置。但是,当您插入地址时,您不会针对客户端id设置值,并且客户端id不能为NULL

可能的解决方案 在地址插入查询中设置客户端id 在表架构中,client_id允许NULL或设置默认值
您需要确保已发送客户端id。使用调试工具包栏检查历史记录,选择POST请求,然后转到Sql日志

必须有这样的查询:

INSERT INTO clients_address (
  client_id, address, modified
) 
VALUES 
  (
    61, 'my address', "123..."
  )
INSERT INTO clients_address (address_line_1, ..., contact_name, CLIENT_ID, default_address)
VALUES (:c0, :c1, :c2, :c3, :c4, :c5, :c6, :c7, :c8, :c9)
如果不是,也许你的表格有问题。 您的查询必须如下所示:

INSERT INTO clients_address (
  client_id, address, modified
) 
VALUES 
  (
    61, 'my address', "123..."
  )
INSERT INTO clients_address (address_line_1, ..., contact_name, CLIENT_ID, default_address)
VALUES (:c0, :c1, :c2, :c3, :c4, :c5, :c6, :c7, :c8, :c9)
如果要添加地址独立地址控制器添加方法,则必须在窗体上手动指定客户端id,或者根据参数从隐藏字段中指定客户端id,这样它将在添加和编辑方法上创建客户端列表

如果您要将客户机表单中的地址作为关联添加,那么CakePHP文档上就是一些很好的例子