CakePHP Save hasOne data:约束错误
嘿,我是CakePHP新手,我想知道为什么我的代码不起作用:CakePHP Save hasOne data:约束错误,cakephp,Cakephp,嘿,我是CakePHP新手,我想知道为什么我的代码不起作用: $data['Gender'] = array( 'bezeichnung' => $item['person']['GENDER'] ); $data['Client'] = array( 'id' => $item['person']['PERSON_ID'], 'vorname' => $item['person']['FIRSTNAME'], 'nachn
$data['Gender'] = array(
'bezeichnung' => $item['person']['GENDER']
);
$data['Client'] = array(
'id' => $item['person']['PERSON_ID'],
'vorname' => $item['person']['FIRSTNAME'],
'nachname' => $item['person']['LASTNAME'],
'gender_id' => $this->Client->Gender->id
);
$this->Client->create();
$this->Client->saveAll($data);
我想使用saveAll命令在数据库中创建一个新条目,其中$data包含所有相关数据
我得到的错误如下:
SQLSTATE[23000]:完整性约束冲突:1452无法添加或更新子行:外键约束失败
我的客户模型:
public $hasOne = array(
'Gender' => array(
'className' => 'Gender',
'foreignKey' => 'gender_id'
)
);
我的性别模型:
public $tablePrefix = 'fixed_';
public $validate = array(
'bezeichnung' => 'isUnique'
);
不要在数据['Client']上设置
gender\u id
,这是自动的,我收到了相同的错误:SQLSTATE[23000]:完整性约束冲突:1452无法添加或更新子行:外键约束失败允许您更新您的问题,指示您收到的错误以及您的模型代码:)?好了。我无法理解此Gender
您要保存,它始终是表中的新行还是仅是一个关系?我的意思是,你的性别模型会给每个客户一行吗?