尝试将记录插入表时出现以下错误:
错误:SQLSTATE[23000]:完整性约束违规:1452 无法添加或更新子行:外键约束失败(invoice
. quotes
, CONSTRAINT quotes_ibfk_1
FOREIGN KEY ( contacts_id
) REFERENCES Contacts
( id
))
我在两个表“联系人”和“报价”之间建立了关系。'quotes' 有一个外键设置 contacts_id。
我的引号控制器中的 Add 方法如下所示:
public function add() {
$this->log('Quote Controller --> Add Method...1');
$this->log($this->request->data);
if ($this->request->is('post')) {
$this->Quote->create(); // This line writes the details to the database.
if ($this->Quote->save($this->request->data)) {
$this->Session->setFlash('Your quote has been saved.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to add your quote.');
}
}
}
任何帮助表示赞赏。